Support upgrade API

Task: 30168
Story: 2002210

Change-Id: I458985f97e1e9bbe89702ce04e74bdcf66e36244
This commit is contained in:
Feilong Wang 2019-03-26 06:01:54 +13:00
parent ba231d0046
commit 6b756aa75f
5 changed files with 143 additions and 0 deletions

View File

@ -413,3 +413,45 @@ class ResizeCluster(command.Command):
parsed_args.nodegroup)
print("Request to resize cluster %s has been accepted." %
parsed_args.cluster)
class UpgradeCluster(command.Command):
_description = _("Upgrade a Cluster")
def get_parser(self, prog_name):
parser = super(UpgradeCluster, self).get_parser(prog_name)
parser.add_argument(
'cluster',
metavar='<cluster>',
help=_('The name or UUID of cluster to update'))
parser.add_argument(
'cluster_template',
help=_("The new cluster template ID will be upgraded to."))
parser.add_argument(
'--max-batch-size',
metavar='<max_batch_size>',
type=int,
default=1,
help=_("The max batch size for upgrading each time."))
parser.add_argument(
'--nodegroup',
metavar='<nodegroup>',
help=_('The name or UUID of the nodegroup of current cluster.'))
return parser
def take_action(self, parsed_args):
self.log.debug("take_action(%s)", parsed_args)
mag_client = self.app.client_manager.container_infra
cluster = mag_client.clusters.get(parsed_args.cluster)
mag_client.clusters.upgrade(cluster.uuid,
parsed_args.cluster_template,
parsed_args.max_batch_size,
parsed_args.nodegroup)
print("Request to upgrade cluster %s has been accepted." %
parsed_args.cluster)

View File

@ -479,3 +479,66 @@ export KUBECONFIG={}/config
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(exceptions.CommandError,
self.cmd.take_action, parsed_args)
class TestClusterResize(TestCluster):
def setUp(self):
super(TestClusterResize, self).setUp()
self.cluster = mock.Mock()
self.cluster.uuid = "UUID1"
self.clusters_mock.resize = mock.Mock()
self.clusters_mock.resize.return_value = None
self.clusters_mock.get = mock.Mock()
self.clusters_mock.get.return_value = self.cluster
# Get the command object to test
self.cmd = osc_clusters.ResizeCluster(self.app, None)
def test_cluster_resize_pass(self):
arglist = ['foo', '2']
verifylist = [
('cluster', 'foo'),
('node_count', 2),
('nodes_to_remove', None),
('nodegroup', None)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.clusters_mock.resize.assert_called_with(
"UUID1", 2, None, None
)
class TestClusterUpgrade(TestCluster):
def setUp(self):
super(TestClusterUpgrade, self).setUp()
self.cluster = mock.Mock()
self.cluster.uuid = "UUID1"
self.clusters_mock.upgrade = mock.Mock()
self.clusters_mock.upgrade.return_value = None
self.clusters_mock.get = mock.Mock()
self.clusters_mock.get.return_value = self.cluster
# Get the command object to test
self.cmd = osc_clusters.UpgradeCluster(self.app, None)
def test_cluster_upgrade_pass(self):
cluster_template_id = 'TEMPLATE_ID'
arglist = ['foo', cluster_template_id]
verifylist = [
('cluster', 'foo'),
('cluster_template', cluster_template_id),
('max_batch_size', 1),
('nodegroup', None)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.clusters_mock.upgrade.assert_called_with(
"UUID1", cluster_template_id, 1, None
)

View File

@ -58,6 +58,10 @@ RESIZED_CLUSTER = copy.deepcopy(CLUSTER1)
RESIZED_NODE_COUNT = 5
UPDATED_CLUSTER['node_count'] = RESIZED_NODE_COUNT
UPGRADED_CLUSTER = copy.deepcopy(CLUSTER1)
UPGRADED_TO_TEMPLATE = "eabbc463-0d3f-49dc-8519-cb6b59507bd6"
UPGRADED_CLUSTER['cluster_template_id'] = UPGRADED_TO_TEMPLATE
fake_responses = {
'/v1/clusters':
{
@ -155,6 +159,13 @@ fake_responses = {
{},
UPDATED_CLUSTER
),
},
'/v1/clusters/%s/actions/upgrade' % CLUSTER1['uuid']:
{
'POST': (
{},
UPGRADED_CLUSTER
),
}
}
@ -376,3 +387,14 @@ class ClusterManagerTest(testtools.TestCase):
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(RESIZED_NODE_COUNT, cluster.node_count)
def test_cluster_upgrade(self):
body = {'cluster_template': UPGRADED_TO_TEMPLATE,
'max_batch_size': 1}
cluster = self.mgr.upgrade(CLUSTER1["uuid"], **body)
expect = [
('POST', '/v1/clusters/%s/actions/upgrade' % CLUSTER1['uuid'],
{}, body),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(UPGRADED_TO_TEMPLATE, cluster.cluster_template_id)

View File

@ -47,3 +47,18 @@ class ClusterManager(baseunit.BaseTemplateManager):
if resp_body:
return self.resource_class(self, resp_body)
def upgrade(self, cluster_uuid, cluster_template,
max_batch_size=1, nodegroup=None):
url = self._path(cluster_uuid) + "/actions/upgrade"
post_body = {"cluster_template": cluster_template}
if max_batch_size:
post_body.update({"max_batch_size": max_batch_size})
if nodegroup:
post_body.update({"nodegroup": nodegroup})
resp, resp_body = self.api.json_request("POST", url, body=post_body)
if resp_body:
return self.resource_class(self, resp_body)

View File

@ -44,6 +44,7 @@ openstack.container_infra.v1 =
coe_cluster_update = magnumclient.osc.v1.clusters:UpdateCluster
coe_cluster_config = magnumclient.osc.v1.clusters:ConfigCluster
coe_cluster_resize = magnumclient.osc.v1.clusters:ResizeCluster
coe_cluster_upgrade = magnumclient.osc.v1.clusters:UpgradeCluster
coe_ca_rotate = magnumclient.osc.v1.certificates:RotateCa
coe_ca_show = magnumclient.osc.v1.certificates:ShowCa
coe_ca_sign = magnumclient.osc.v1.certificates:SignCa