Skip to content
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

Merged
merged 3 commits into from
Jun 15, 2018

Conversation

jrha
Copy link
Member

@jrha jrha commented Jun 8, 2018

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.

  • Fix mixed source indentation
  • Switch to CAF for all file interaction and declare NoAction support.
  • Factor out filelist read/write to seperate functions.
  • Add a set of basic Configure unit tests.

@jrha jrha force-pushed the sysconfig_modernise branch from fe4e6d5 to a9dd6b5 Compare June 11, 2018 14:23
@jrha jrha requested a review from stdweird June 11, 2018 14:29
@jrha jrha force-pushed the sysconfig_modernise branch 3 times, most recently from 7af84a9 to a57762f Compare June 11, 2018 15:59
@@ -9,9 +9,7 @@ include 'quattor/schema';

type component_sysconfig = {
include structure_component
'files' ? string{}{}
'files' ? string(1..){}{}
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@jrha
Copy link
Member Author

jrha commented Jun 13, 2018

@ned21 is the schema easier to follow now?

@jrha jrha force-pushed the sysconfig_modernise branch 2 times, most recently from d8a4d6d to a2475b2 Compare June 13, 2018 13:54
@jrha
Copy link
Member Author

jrha commented Jun 13, 2018

Also @stdweird is it worth me moving the pod into the pm?

@stdweird
Copy link
Member

@jrha yes, it's very small anyway

type component_sysconfig = {
include structure_component
'files' ? string{}{}
@{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one line?

@jrha jrha force-pushed the sysconfig_modernise branch from a2475b2 to d6c5be9 Compare June 13, 2018 13:58
# 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");
Copy link
Member

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");
Copy link
Member

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) {
Copy link
Member

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}}) {
Copy link
Member

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"})) {
Copy link
Member

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";
Copy link
Member

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}) {
Copy link
Member

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"})) {
Copy link
Member

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");
Copy link
Member

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;
Copy link
Member

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;
Copy link
Contributor

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 >>
Copy link
Member

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

Copy link
Member Author

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>/ >>
Copy link
Member

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(
Copy link
Member

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)

Copy link
Member Author

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 "

Copy link
Member Author

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

Copy link
Member

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 ...

Copy link
Member

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....

Copy link
Member Author

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> ...

Copy link
Member

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

stdweird
stdweird previously approved these changes Jun 14, 2018
Copy link
Member

@stdweird stdweird left a 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrha well, almost nice. can you also add

our $NoActionSupported = 1;

(as per @ned21 request)

Copy link
Member Author

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?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jrha jrha added this to the 18.6 milestone Jun 14, 2018
@stdweird
Copy link
Member

@ned21 ok for you?
@jrha do you plan to squash any commits?

ned21
ned21 previously approved these changes Jun 14, 2018
@ned21
Copy link
Contributor

ned21 commented Jun 14, 2018

Looks like at least two commits have been described as to be squashed prior to merge.

@jrha
Copy link
Member Author

jrha commented Jun 15, 2018

Indeed, I'll apply some judicious squashing.

jrha added 2 commits June 15, 2018 11:41
* 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.
@jrha
Copy link
Member Author

jrha commented Jun 15, 2018

All rebased and squashed, have at it.

@stdweird stdweird merged commit 951b1f1 into quattor:master Jun 15, 2018
@jrha jrha deleted the sysconfig_modernise branch June 15, 2018 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants