Merge "Add --keypair-id for cluster-create"

This commit is contained in:
Jenkins 2016-10-10 08:35:49 +00:00 committed by Gerrit Code Review
commit f31816cd92
6 changed files with 80 additions and 29 deletions

View File

@ -245,6 +245,17 @@ class ClusterManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertTrue(cluster)
def test_cluster_create_with_keypair(self):
cluster_with_keypair = dict()
cluster_with_keypair.update(CREATE_CLUSTER)
cluster_with_keypair['keypair'] = 'test_key'
cluster = self.mgr.create(**cluster_with_keypair)
expect = [
('POST', '/v1/clusters', {}, cluster_with_keypair),
]
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

@ -24,6 +24,7 @@ class FakeCluster(Cluster):
def __init__(self, manager=None, info={}, **kwargs):
Cluster.__init__(self, manager=manager, info=info)
self.uuid = kwargs.get('uuid', 'x')
self.keypair = kwargs.get('keypair_id', 'x')
self.name = kwargs.get('name', 'x')
self.cluster_template_id = kwargs.get('cluster_template_id', 'x')
self.stack_id = kwargs.get('stack_id', 'x')
@ -55,14 +56,14 @@ 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 | node_count | '
keyword=('\n| uuid | name | keypair_id | node_count | '
'master_count | status |\n'))
# Output should be
# +------+------+------------+--------------+--------+
# | uuid | name | node_count | master_count | status |
# +------+------+------------+--------------+--------+
# | x | x | x | x | x |
# +------+------+------------+--------------+--------+
# +------+------+------------+--------------+--------------+--------+
# | uuid | name | keypair_id | node_count | master_count | status |
# +------+------+------------+--------------+--------------+--------+
# | x | x | x | x | x | x |
# +------+------+------------+--------------+--------------+--------+
self.assertTrue(mock_list.called)
@mock.patch('magnumclient.v1.clusters.ClusterManager.list')
@ -102,6 +103,10 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
self._test_arg_success('cluster-create --cluster-template xxx')
self.assertTrue(mock_create.called)
self._test_arg_success('cluster-create --cluster-template xxx '
'--keypair-id x')
self.assertTrue(mock_create.called)
self._test_arg_success('cluster-create --name test '
'--cluster-template xxx')
self.assertTrue(mock_create.called)
@ -149,6 +154,12 @@ class ShellTest(shell_test_base.TestCommandLineArgument):
self._mandatory_arg_error)
self.assertFalse(mock_create.called)
@mock.patch('magnumclient.v1.clusters.ClusterManager.create')
def test_cluster_create_failure_only_keypair(self, mock_create):
self._test_arg_failure('cluster-create --keypair-id test',
self._mandatory_arg_error)
self.assertFalse(mock_create.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

@ -29,7 +29,6 @@ CLUSTERTEMPLATE1 = {
'image_id': 'clustertemplate1-image',
'master_flavor_id': 'm1.tiny',
'flavor_id': 'm1.small',
'keypair_id': 'keypair1',
'external_network_id': 'd1f02cfb-d27f-4068-9332-84d907cb0e21',
'fixed_network': 'private',
'fixed_subnet': 'private-subnet',
@ -57,7 +56,6 @@ CLUSTERTEMPLATE2 = {
'image_id': 'clustertemplate2-image',
'flavor_id': 'm2.small',
'master_flavor_id': 'm2.tiny',
'keypair_id': 'keypair2',
'external_network_id': 'd1f02cfb-d27f-4068-9332-84d907cb0e22',
'fixed_network': 'private2',
'network_driver': 'flannel',
@ -370,6 +368,23 @@ class ClusterTemplateManagerTest(testtools.TestCase):
self.assertEqual(CLUSTERTEMPLATE1['docker_storage_driver'],
cluster_template.docker_storage_driver)
def test_clustertemplate_create_with_keypair(self):
cluster_template_with_keypair = dict()
cluster_template_with_keypair.update(CREATE_CLUSTERTEMPLATE)
cluster_template_with_keypair['keypair_id'] = 'test_key'
cluster_template = self.mgr.create(**cluster_template_with_keypair)
expect = [
('POST', '/v1/clustertemplates', {},
cluster_template_with_keypair),
]
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

@ -30,16 +30,17 @@ def _show_cluster_template(cluster_template):
@utils.arg('--image-id',
required=True,
metavar='<image-id>',
help='The name or UUID of the base image to customize for the bay.')
help='The name or UUID of the base image to customize for the '
'Cluster.')
@utils.arg('--keypair-id',
required=True,
required=False,
metavar='<keypair-id>',
help='The name or UUID of the SSH keypair to load into the'
' Bay nodes.')
help='The name or UUID of the SSH keypair to load into the '
'Cluster nodes.')
@utils.arg('--external-network-id',
required=True,
metavar='<external-network-id>',
help='The external Neutron network ID to connect to this bay'
help='The external Neutron network ID to connect to this Cluster'
' model.')
@utils.arg('--coe',
required=True,
@ -47,11 +48,11 @@ def _show_cluster_template(cluster_template):
help='Specify the Container Orchestration Engine to use.')
@utils.arg('--fixed-network',
metavar='<fixed-network>',
help='The private Neutron network name to connect to this bay'
help='The private Neutron network name to connect to this Cluster'
' model.')
@utils.arg('--fixed-subnet',
metavar='<fixed-subnet>',
help='The private Neutron subnet name to connect to bay.')
help='The private Neutron subnet name to connect to Cluster.')
@utils.arg('--network-driver',
metavar='<network-driver>',
help='The network driver name for instantiating container'
@ -67,11 +68,11 @@ def _show_cluster_template(cluster_template):
@utils.arg('--flavor-id',
metavar='<flavor-id>',
default='m1.medium',
help='The nova flavor id to use when launching the bay.')
help='The nova flavor id to use when launching the Cluster.')
@utils.arg('--master-flavor-id',
metavar='<master-flavor-id>',
help='The nova flavor id to use when launching the master node '
'of the bay.')
'of the Cluster.')
@utils.arg('--docker-volume-size',
metavar='<docker-volume-size>',
type=int,
@ -84,13 +85,13 @@ def _show_cluster_template(cluster_template):
'overlay. Default: devicemapper')
@utils.arg('--http-proxy',
metavar='<http-proxy>',
help='The http_proxy address to use for nodes in bay.')
help='The http_proxy address to use for nodes in Cluster.')
@utils.arg('--https-proxy',
metavar='<https-proxy>',
help='The https_proxy address to use for nodes in bay.')
help='The https_proxy address to use for nodes in Cluster.')
@utils.arg('--no-proxy',
metavar='<no-proxy>',
help='The no_proxy address to use for nodes in bay.')
help='The no_proxy address to use for nodes in Cluster.')
@utils.arg('--labels', metavar='<KEY1=VALUE1,KEY2=VALUE2;KEY3=VALUE3...>',
action='append', default=[],
help='Arbitrary labels in the form of key=value pairs '
@ -98,13 +99,13 @@ def _show_cluster_template(cluster_template):
'May be used multiple times.')
@utils.arg('--tls-disabled',
action='store_true', default=False,
help='Disable TLS in the Bay.')
help='Disable TLS in the Cluster.')
@utils.arg('--public',
action='store_true', default=False,
help='Make cluster template public.')
@utils.arg('--registry-enabled',
action='store_true', default=False,
help='Enable docker registry in the Bay')
help='Enable docker registry in the Cluster')
@utils.arg('--server-type',
metavar='<server-type>',
default='vm',
@ -113,11 +114,11 @@ def _show_cluster_template(cluster_template):
'default server type will be vm.')
@utils.arg('--master-lb-enabled',
action='store_true', default=False,
help='Indicates whether created bays should have a load balancer '
'for master nodes or not.')
help='Indicates whether created Clusters should have a load '
'balancer for master nodes or not.')
@utils.arg('--floating-ip-enabled',
action='store_true', default=True,
help='Indicates whether created bays should have a floating ip'
help='Indicates whether created Clusters should have a floating ip'
'or not.')
def do_cluster_template_create(cs, args):
"""Create a cluster template."""

View File

@ -18,6 +18,7 @@ from magnumclient.v1 import baseunit
CREATION_ATTRIBUTES = baseunit.CREATION_ATTRIBUTES
CREATION_ATTRIBUTES.append('cluster_template_id')
CREATION_ATTRIBUTES.append('create_timeout')
CREATION_ATTRIBUTES.append('keypair')
class Cluster(baseunit.BaseTemplate):

View File

@ -52,9 +52,9 @@ def _show_cluster(cluster):
default=None,
metavar='<fields>',
help=_('Comma-separated list of fields to display. '
'Available fields: uuid, name, baymodel_id, stack_id, '
'status, master_count, node_count, links, '
'cluster_create_timeout'
'Available fields: uuid, name, cluster_template_id, '
'stack_id, status, master_count, node_count, links, '
'create_timeout'
)
)
def do_cluster_list(cs, args):
@ -62,12 +62,19 @@ def do_cluster_list(cs, args):
clusters = cs.clusters.list(marker=args.marker, limit=args.limit,
sort_key=args.sort_key,
sort_dir=args.sort_dir)
columns = ['uuid', 'name', 'node_count', 'master_count', 'status']
columns = [
'uuid', 'name', 'keypair', 'node_count', 'master_count', 'status'
]
columns += utils._get_list_table_columns_and_formatters(
args.fields, clusters,
exclude_fields=(c.lower() for c in columns))[0]
labels = columns[:]
labels[2] = 'keypair_id'
utils.print_list(clusters, columns,
{'versions': magnum_utils.print_list_field('versions')},
field_labels=labels,
sortby_index=None)
@ -78,6 +85,10 @@ def do_cluster_list(cs, args):
required=True,
metavar='<cluster_template>',
help='ID or name of the cluster template.')
@utils.arg('--keypair-id',
metavar='<keypair_id>',
default=None,
help='Name of the keypair to use for this cluster.')
@utils.arg('--node-count',
metavar='<node-count>',
type=int,
@ -104,6 +115,7 @@ def do_cluster_create(cs, args):
opts = {}
opts['name'] = args.name
opts['cluster_template_id'] = cluster_template.uuid
opts['keypair'] = args.keypair_id
opts['node_count'] = args.node_count
opts['master_count'] = args.master_count
opts['discovery_url'] = args.discovery_url