From cd8571407850977b0d854c9e4557a0e5bd92e03a Mon Sep 17 00:00:00 2001 From: K Jonathan Harker Date: Thu, 8 Jan 2015 15:55:22 -0500 Subject: [PATCH] Fix nodepool --version Currently, the `nodepool --version` command prints a usage message followed by 'nodepool: error: too few arguments' because we are not specifying a subcommand. The proper way to do this is to use the version action in argparser rather than store_true with some logic. Add version_info so it can successfully be imported and a version action to print the imported string. Change-Id: Ic5437d508b27fe4a8e02361cfe345c1f741d3c48 --- nodepool/cmd/nodepoolcmd.py | 9 +++------ nodepool/version.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 nodepool/version.py diff --git a/nodepool/cmd/nodepoolcmd.py b/nodepool/cmd/nodepoolcmd.py index 7154a1a75..461eb32ad 100644 --- a/nodepool/cmd/nodepoolcmd.py +++ b/nodepool/cmd/nodepoolcmd.py @@ -21,6 +21,7 @@ import time from nodepool import nodedb from nodepool import nodepool +from nodepool.version import version_info as npc_version_info from prettytable import PrettyTable @@ -33,7 +34,8 @@ class NodePoolCmd(object): parser.add_argument('-c', dest='config', default='/etc/nodepool/nodepool.yaml', help='path to config file') - parser.add_argument('--version', dest='version', action='store_true', + parser.add_argument('--version', action='version', + version=npc_version_info.version_string(), help='show version') parser.add_argument('--debug', dest='debug', action='store_true', help='show DEBUG level logging') @@ -316,11 +318,6 @@ class NodePoolCmd(object): self.pool.deleteImage(self.args.id) def main(self): - if self.args.version: - from nodepool.version import version_info as npc_version_info - print "Nodepool version: %s" % npc_version_info.version_string() - return(0) - self.pool = nodepool.NodePool(self.args.config) config = self.pool.loadConfig() self.pool.reconfigureDatabase(config) diff --git a/nodepool/version.py b/nodepool/version.py new file mode 100644 index 000000000..4ac2dadfb --- /dev/null +++ b/nodepool/version.py @@ -0,0 +1,17 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import pbr.version + +version_info = pbr.version.VersionInfo('nodepool')