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
This commit is contained in:
K Jonathan Harker 2015-01-08 15:55:22 -05:00
parent 71e9ed7545
commit cd85714078
2 changed files with 20 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import time
from nodepool import nodedb from nodepool import nodedb
from nodepool import nodepool from nodepool import nodepool
from nodepool.version import version_info as npc_version_info
from prettytable import PrettyTable from prettytable import PrettyTable
@ -33,7 +34,8 @@ class NodePoolCmd(object):
parser.add_argument('-c', dest='config', parser.add_argument('-c', dest='config',
default='/etc/nodepool/nodepool.yaml', default='/etc/nodepool/nodepool.yaml',
help='path to config file') 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') help='show version')
parser.add_argument('--debug', dest='debug', action='store_true', parser.add_argument('--debug', dest='debug', action='store_true',
help='show DEBUG level logging') help='show DEBUG level logging')
@ -316,11 +318,6 @@ class NodePoolCmd(object):
self.pool.deleteImage(self.args.id) self.pool.deleteImage(self.args.id)
def main(self): 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) self.pool = nodepool.NodePool(self.args.config)
config = self.pool.loadConfig() config = self.pool.loadConfig()
self.pool.reconfigureDatabase(config) self.pool.reconfigureDatabase(config)

17
nodepool/version.py Normal file
View File

@ -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')