Merge "Add --docker-volume-size for cluster-create"

This commit is contained in:
Jenkins 2017-06-16 14:09:07 +00:00 committed by Gerrit Code Review
commit a0e89b2848
5 changed files with 56 additions and 10 deletions

View File

@ -263,6 +263,17 @@ class ClusterManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(cluster)
def test_cluster_create_with_docker_volume_size(self):
cluster_with_volume_size = dict()
cluster_with_volume_size.update(CREATE_CLUSTER)
cluster_with_volume_size['docker_volume_size'] = 20
cluster = self.mgr.create(**cluster_with_volume_size)
expect = [
('POST', '/v1/clusters', {}, cluster_with_volume_size),
]
self.assertEqual(expect, self.api.calls)
self.assertTrue(cluster)
def test_cluster_create_with_discovery_url(self):
cluster_with_discovery = dict()
cluster_with_discovery.update(CREATE_CLUSTER)

View File

@ -26,6 +26,7 @@ class FakeCluster(Cluster):
Cluster.__init__(self, manager=manager, info=info)
self.uuid = kwargs.get('uuid', 'x')
self.keypair = kwargs.get('keypair', 'x')
self.docker_volume_size = kwargs.get('docker_volume_size', 3)
self.name = kwargs.get('name', 'x')
self.cluster_template_id = kwargs.get('cluster_template_id', 'x')
self.stack_id = kwargs.get('stack_id', 'x')
@ -56,6 +57,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
def _get_expected_args_create(self, cluster_template_id, name=None,
master_count=1, node_count=1,
create_timeout=60, keypair=None,
docker_volume_size=None,
discovery_url=None):
expected_args = {}
expected_args['name'] = name
@ -65,6 +67,7 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
expected_args['create_timeout'] = create_timeout
expected_args['discovery_url'] = discovery_url
expected_args['keypair'] = keypair
expected_args['docker_volume_size'] = docker_volume_size
return expected_args
@ -90,14 +93,8 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
mock_list.return_value = [FakeCluster()]
self._test_arg_success(
'cluster-list --fields status,status,status,name',
keyword=('\n| uuid | name | keypair | node_count | '
'master_count | status |\n'))
# Output should be
# +------+------+---------+--------------+--------------+--------+
# | uuid | name | keypair | node_count | master_count | status |
# +------+------+---------+--------------+--------------+--------+
# | x | x | x | x | x | x |
# +------+------+---------+--------------+--------------+--------+
keyword=('\n| uuid | name | keypair | docker_volume_size | '
'node_count | master_count | status |\n'))
expected_args = self._get_expected_args_list()
mock_list.assert_called_once_with(**expected_args)
@ -152,6 +149,12 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
keypair='x')
mock_create.assert_called_with(**expected_args)
self._test_arg_success('cluster-create --cluster-template xxx '
'--docker-volume-size 20')
expected_args = self._get_expected_args_create('xxx',
docker_volume_size=20)
mock_create.assert_called_with(**expected_args)
self._test_arg_success('cluster-create test '
'--cluster-template xxx')
expected_args = self._get_expected_args_create('xxx',
@ -271,6 +274,12 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
self._mandatory_arg_error)
mock_create.assert_not_called()
@mock.patch('magnumclient.v1.clusters.ClusterManager.create')
def test_cluster_create_failure_only_docker_volume_size(self, mock_create):
self._test_arg_failure('cluster-create --docker_volume_size 20',
self._mandatory_arg_error)
mock_create.assert_not_called()
@mock.patch('magnumclient.v1.clusters.ClusterManager.create')
def test_cluster_create_failure_only_node_count(self, mock_create):
self._test_arg_failure('cluster-create --node-count 1',

View File

@ -61,7 +61,7 @@ CLUSTERTEMPLATE2 = {
'network_driver': 'flannel',
'volume_driver': 'cinder',
'dns_nameserver': '8.8.1.2',
'docker_volume_size': '50',
'docker_volume_size': '71',
'docker_storage_driver': 'overlay',
'coe': 'kubernetes',
'labels': 'key2=val2,key22=val22',
@ -385,6 +385,24 @@ class ClusterTemplateManagerTest(testtools.TestCase):
self.assertEqual(CLUSTERTEMPLATE1['docker_storage_driver'],
cluster_template.docker_storage_driver)
def test_clustertemplate_create_with_docker_volume_size(self):
cluster_template_with_docker_volume_size = dict()
cluster_template_with_docker_volume_size.update(CREATE_CLUSTERTEMPLATE)
cluster_template_with_docker_volume_size['docker_volume_size'] = 11
cluster_template = self.mgr.create(
**cluster_template_with_docker_volume_size)
expect = [
('POST', '/v1/clustertemplates', {},
cluster_template_with_docker_volume_size),
]
self.assertEqual(expect, self.api.calls)
self.assertTrue(cluster_template)
self.assertEqual(CLUSTERTEMPLATE1['docker_volume_size'],
cluster_template.docker_volume_size)
self.assertEqual(CLUSTERTEMPLATE1['docker_storage_driver'],
cluster_template.docker_storage_driver)
def test_clustertemplate_create_fail(self):
CREATE_CLUSTERTEMPLATE_FAIL = copy.deepcopy(CREATE_CLUSTERTEMPLATE)
CREATE_CLUSTERTEMPLATE_FAIL["wrong_key"] = "wrong"

View File

@ -19,6 +19,7 @@ CREATION_ATTRIBUTES = baseunit.CREATION_ATTRIBUTES
CREATION_ATTRIBUTES.append('cluster_template_id')
CREATION_ATTRIBUTES.append('create_timeout')
CREATION_ATTRIBUTES.append('keypair')
CREATION_ATTRIBUTES.append('docker_volume_size')
class Cluster(baseunit.BaseTemplate):

View File

@ -70,7 +70,8 @@ def do_cluster_list(cs, args):
sort_key=args.sort_key,
sort_dir=args.sort_dir)
columns = [
'uuid', 'name', 'keypair', 'node_count', 'master_count', 'status'
'uuid', 'name', 'keypair', 'docker_volume_size', 'node_count',
'master_count', 'status'
]
columns += utils._get_list_table_columns_and_formatters(
args.fields, clusters,
@ -108,6 +109,11 @@ def do_cluster_list(cs, args):
metavar='<keypair>',
default=None,
help=_('Name of the keypair to use for this cluster.'))
@utils.arg('--docker-volume-size',
metavar='<docker-volume-size>',
type=int,
default=None,
help=_('The size in GB for the docker volume to use'))
@utils.arg('--node-count',
metavar='<node-count>',
type=int,
@ -138,6 +144,7 @@ def do_cluster_create(cs, args):
opts['name'] = args.positional_name or args.name
opts['cluster_template_id'] = cluster_template.uuid
opts['keypair'] = args.keypair
opts['docker_volume_size'] = args.docker_volume_size
opts['node_count'] = args.node_count
opts['master_count'] = args.master_count
opts['discovery_url'] = args.discovery_url