-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ncm-sysconfig: Cleanup and modernise codebase #1288
Conversation
fe4e6d5
to
a9dd6b5
Compare
7af84a9
to
a57762f
Compare
@@ -9,9 +9,7 @@ include 'quattor/schema'; | |||
|
|||
type component_sysconfig = { | |||
include structure_component | |||
'files' ? string{}{} | |||
'files' ? string(1..){}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an annotation describing the structure that is required here in more detail? Also what version of panc does this require? Please call out in the commit log since I am not sure we have got around to deploying the latest release yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll improve the docs.
It shouldn't need a recent pan compiler, string length validation has been around forever and the double nested dict comes from the original code from CERN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also break the type apart to make it clearer.
@ned21 is the schema easier to follow now? |
d8a4d6d
to
a2475b2
Compare
Also @stdweird is it worth me moving the |
@jrha yes, it's very small anyway |
type component_sysconfig = { | ||
include structure_component | ||
'files' ? string{}{} | ||
@{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one line?
a2475b2
to
d6c5be9
Compare
# previously managed by this component. These will have to | ||
# be deleted if no longer in the configuration. | ||
my %filelist; | ||
my $fh = CAF::FileReader->open ("$SYSCONFIGDIR/ncm-sysconfig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add , log => $self
my ($self, %filelist) = @_; | ||
|
||
# Write the list of managed configuration files. | ||
my $fh = CAF::FileWriter->open("$SYSCONFIGDIR/ncm-sysconfig"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add , log => $self
|
||
# Write the list of managed configuration files. | ||
my $fh = CAF::FileWriter->open("$SYSCONFIGDIR/ncm-sysconfig"); | ||
for my $file (keys %filelist) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i prefer foreach
(altough it's identical); but do sort the keys for reproducibility
|
||
# Loop over all of the defined files, writing each as necessary. | ||
if ( $sysconfig_config->{files} ) { | ||
for my $file (sort keys %{$sysconfig_config->{files}}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach
?
my $contents = ''; | ||
|
||
# Add the prologue if it exists. | ||
if (defined($pairs->{"prologue"})) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for "
inside the {}
|
||
# Add the prologue if it exists. | ||
if (defined($pairs->{"prologue"})) { | ||
$contents .= $pairs->{"prologue"} . "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make that "$pairs->{prologue}\n";
(at least i find that more readable)
} | ||
|
||
# Loop over the pairs adding the information to the file. | ||
for my $key (sort keys %{$pairs}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just %$pairs
} | ||
|
||
# Add the epilogue if it exists. | ||
if (defined($pairs->{"epilogue"})) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same remarks as prologue
} | ||
|
||
# Now actually update the file, if needed. | ||
my $fh = CAF::FileWriter->open("$SYSCONFIGDIR/$file", backup=>".old"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add , log => $self
, also space around the =>
my $fh = CAF::FileWriter->open("$SYSCONFIGDIR/$file", backup=>".old"); | ||
print $fh $contents; | ||
$fh->close(); | ||
undef $fh; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
our $EC = LC::Exception::Context->new->will_store_all; | ||
|
||
use LC::Check; | ||
use CAF::FileReader; | ||
use CAF::FileWriter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this NoAction safe and if so does it need to be included here? (I assume PMComponent macro doesn't make that assumption.
|
||
=over | ||
|
||
=item * C<< /software/components/sysconfig/files >> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for schema annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh fine
This is an dict which has the file name (unescaped) as the key, and | ||
the content information as the value. The value is an dict. | ||
|
||
=item * C<< /software/components/sysconfig/files/<fname>/ >> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, move to schema
|
||
=head1 EXAMPLE | ||
|
||
"/software/components/sysconfig/files/scfg" = dict( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also move to schema (you can add a and @example{}
after the @documentation
of the main component type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? This causes panc
to barf on the "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's happy with the example in the @documentation
block, but not @example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the error message? is it similar to quattor/pan#127?
i'll try to find where i used it ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrha that's strange. i'm fine with it in the @documenation
section, but i thought i already used @example{}
somewhere....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[INFO] --- panc-maven-plugin:10.2:check-syntax (check-generated-pan-syntax) @ sysconfig ---
parse error [/home/centos/configuration-modules-core/ncm-sysconfig/target/pan/components/sysconfig/schema.pan:24.1-34.1]
Encountered " <ERROR> "\' "" at line 2, column 1.
Was expecting one of:
<EOF>
<KEY> ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hah, so it is similar to quattor/pan#127
i made quattor/pan#204 for followup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
use File::Path; | ||
use File::Basename; | ||
Readonly my $QUOTE => "\""; | ||
Readonly my $SYSCONFIGDIR => "/etc/sysconfig"; # The base directory for sysconfig files. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I had added that already... where did it go?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Looks like at least two commits have been described as to be squashed prior to merge. |
Indeed, I'll apply some judicious squashing. |
* Switch to CAF for all file interaction and declare NoAction support. * Use logger with FileWriters * Declare no-action support * Factor out filelist read/write to seperate functions. * Add a set of basic Configure unit tests. * Move pod into main source module * Switch nlists to dicts in pod * Move example to schema and remove redundant pod
* Break apart schema into sub-types for clarification * Disallow empty values * Make use of schema in tests * Add annotations based on paraphrased description from pod.
880e89a
to
aa52055
Compare
All rebased and squashed, have at it. |
As noted in #434 ncm-sysconfig will stay around for the time being, this means the code-base should be kept up-to-date with our current standards for maintainability. This should then allow us to tackle the open issues without introducing (too many) new bugs.