Allow to make operations on a given cluster
Add parameter (`cluster_id`) to the appropriate methods to make possible to perform operations (such as launch deployment, reset environment etc) on a given cluster. Change-Id: I6cc80335cbcdaa11be57e6cfc61ea579a39ac90e Closes-Bug: #1398043
This commit is contained in:
parent
cf3d9641a2
commit
0896ae9cce
|
@ -412,9 +412,11 @@ class EnvironmentManager(object):
|
|||
self.db.commit()
|
||||
return notification
|
||||
|
||||
def create_node_group(self, api=True, expect_errors=False, **kwargs):
|
||||
def create_node_group(self, api=True, expect_errors=False,
|
||||
cluster_id=None, **kwargs):
|
||||
cluster_id = self._get_cluster_by_id(cluster_id).id
|
||||
ng_data = {
|
||||
'cluster_id': self.clusters[0].id,
|
||||
'cluster_id': cluster_id,
|
||||
'name': 'test_ng'
|
||||
}
|
||||
if kwargs:
|
||||
|
@ -867,13 +869,34 @@ class EnvironmentManager(object):
|
|||
if item.get('pk') == pk and item.get('model') == model:
|
||||
return item
|
||||
|
||||
def launch_provisioning_selected(self, nodes_uids=None):
|
||||
def _get_cluster_by_id(self, cluster_id):
|
||||
"""Get cluster by cluster ID.
|
||||
|
||||
Get cluster by cluster ID. If `cluster_id` is `None` then return
|
||||
first cluster from the list.
|
||||
|
||||
:param cluster_id: cluster ID
|
||||
:type cluster_id: int
|
||||
:return: cluster
|
||||
"""
|
||||
if cluster_id is None:
|
||||
return self.clusters[0]
|
||||
|
||||
for cluster in self.clusters:
|
||||
if cluster.id == cluster_id:
|
||||
return cluster
|
||||
|
||||
raise Exception(
|
||||
'Cluster with ID "{0}" was not found.'.format(cluster_id))
|
||||
|
||||
def launch_provisioning_selected(self, nodes_uids=None, cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster = self._get_cluster_by_id(cluster_id)
|
||||
if not nodes_uids:
|
||||
nodes_uids = [n.uid for n in self.clusters[0].nodes]
|
||||
nodes_uids = [n.uid for n in cluster.nodes]
|
||||
action_url = reverse(
|
||||
'ProvisionSelectedNodes',
|
||||
kwargs={'cluster_id': self.clusters[0].id}
|
||||
kwargs={'cluster_id': cluster.id}
|
||||
) + '?nodes={0}'.format(','.join(nodes_uids))
|
||||
resp = self.app.put(
|
||||
action_url,
|
||||
|
@ -891,12 +914,13 @@ class EnvironmentManager(object):
|
|||
"Nothing to provision - try creating cluster"
|
||||
)
|
||||
|
||||
def launch_deployment(self):
|
||||
def launch_deployment(self, cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster_id = self._get_cluster_by_id(cluster_id).id
|
||||
resp = self.app.put(
|
||||
reverse(
|
||||
'ClusterChangesHandler',
|
||||
kwargs={'cluster_id': self.clusters[0].id}),
|
||||
kwargs={'cluster_id': cluster_id}),
|
||||
headers=self.default_headers)
|
||||
|
||||
return self.db.query(Task).filter_by(
|
||||
|
@ -907,12 +931,13 @@ class EnvironmentManager(object):
|
|||
"Nothing to deploy - try creating cluster"
|
||||
)
|
||||
|
||||
def stop_deployment(self):
|
||||
def stop_deployment(self, cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster_id = self._get_cluster_by_id(cluster_id).id
|
||||
resp = self.app.put(
|
||||
reverse(
|
||||
'ClusterStopDeploymentHandler',
|
||||
kwargs={'cluster_id': self.clusters[0].id}),
|
||||
kwargs={'cluster_id': cluster_id}),
|
||||
expect_errors=True,
|
||||
headers=self.default_headers)
|
||||
|
||||
|
@ -924,12 +949,13 @@ class EnvironmentManager(object):
|
|||
"Nothing to stop - try creating cluster"
|
||||
)
|
||||
|
||||
def reset_environment(self, expect_http=202):
|
||||
def reset_environment(self, expect_http=202, cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster_id = self._get_cluster_by_id(cluster_id).id
|
||||
resp = self.app.put(
|
||||
reverse(
|
||||
'ClusterResetHandler',
|
||||
kwargs={'cluster_id': self.clusters[0].id}),
|
||||
kwargs={'cluster_id': cluster_id}),
|
||||
expect_errors=True,
|
||||
headers=self.default_headers)
|
||||
self.tester.assertEqual(resp.status_code, expect_http)
|
||||
|
@ -943,12 +969,13 @@ class EnvironmentManager(object):
|
|||
"Nothing to reset - try creating cluster"
|
||||
)
|
||||
|
||||
def delete_environment(self, expect_http=202):
|
||||
def delete_environment(self, expect_http=202, cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster_id = self._get_cluster_by_id(cluster_id).id
|
||||
resp = self.app.delete(
|
||||
reverse(
|
||||
'ClusterHandler',
|
||||
kwargs={'obj_id': self.clusters[0].id}),
|
||||
kwargs={'obj_id': cluster_id}),
|
||||
expect_errors=True,
|
||||
headers=self.default_headers)
|
||||
self.tester.assertEqual(resp.status_code, expect_http)
|
||||
|
@ -962,16 +989,18 @@ class EnvironmentManager(object):
|
|||
"Nothing to delete - try creating cluster"
|
||||
)
|
||||
|
||||
def update_environment(self, pending_release_id=None, expect_http=202):
|
||||
def update_environment(self, pending_release_id=None, expect_http=202,
|
||||
cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster = self._get_cluster_by_id(cluster_id)
|
||||
if not pending_release_id:
|
||||
pending_release_id = self.clusters[0].release_id
|
||||
self.clusters[0].pending_release_id = pending_release_id
|
||||
pending_release_id = cluster.release_id
|
||||
cluster.pending_release_id = pending_release_id
|
||||
self.db.commit()
|
||||
resp = self.app.put(
|
||||
reverse(
|
||||
'ClusterUpdateHandler',
|
||||
kwargs={'cluster_id': self.clusters[0].id}),
|
||||
kwargs={'cluster_id': cluster.id}),
|
||||
expect_errors=True,
|
||||
headers=self.default_headers)
|
||||
self.tester.assertEqual(expect_http, resp.status_code)
|
||||
|
@ -985,8 +1014,10 @@ class EnvironmentManager(object):
|
|||
"Nothing to update - try creating cluster"
|
||||
)
|
||||
|
||||
def launch_verify_networks(self, data=None, expect_errors=False):
|
||||
def launch_verify_networks(self, data=None, expect_errors=False,
|
||||
cluster_id=None):
|
||||
if self.clusters:
|
||||
cluster = self._get_cluster_by_id(cluster_id)
|
||||
net_urls = {
|
||||
"nova_network": {
|
||||
"config": "NovaNetworkConfigurationHandler",
|
||||
|
@ -997,14 +1028,14 @@ class EnvironmentManager(object):
|
|||
"verify": "NeutronNetworkConfigurationVerifyHandler"
|
||||
}
|
||||
}
|
||||
provider = self.clusters[0].net_provider
|
||||
provider = cluster.net_provider
|
||||
if data:
|
||||
nets = jsonutils.dumps(data)
|
||||
else:
|
||||
resp = self.app.get(
|
||||
reverse(
|
||||
net_urls[provider]["config"],
|
||||
kwargs={'cluster_id': self.clusters[0].id}
|
||||
kwargs={'cluster_id': cluster.id}
|
||||
),
|
||||
headers=self.default_headers
|
||||
)
|
||||
|
@ -1014,7 +1045,7 @@ class EnvironmentManager(object):
|
|||
resp = self.app.put(
|
||||
reverse(
|
||||
net_urls[provider]["verify"],
|
||||
kwargs={'cluster_id': self.clusters[0].id}),
|
||||
kwargs={'cluster_id': cluster.id}),
|
||||
nets,
|
||||
headers=self.default_headers,
|
||||
expect_errors=expect_errors,
|
||||
|
|
Loading…
Reference in New Issue