def PUT(self, cluster_id): """:returns: JSONized Task object. :http: * 200 (task successfully executed) * 404 (cluster not found in db) * 400 (failed to execute task) """ cluster = self.get_object_or_404( Cluster, cluster_id, log_404=("warning", "Error: there is no cluster " "with id '{0}' in DB.".format(cluster_id))) if cluster.net_provider == 'nova_network': net_serializer = NovaNetworkConfigurationSerializer elif cluster.net_provider == 'neutron': net_serializer = NeutronNetworkConfigurationSerializer try: network_info = net_serializer.serialize_for_cluster(cluster) logger.info(u"Network info:\n{0}".format( json.dumps(network_info, indent=4))) task_manager = ApplyChangesTaskManager(cluster_id=cluster.id) task = task_manager.execute() except Exception as exc: logger.warn(u'ClusterChangesHandler: error while execution' ' deploy task: {0}'.format(str(exc))) raise web.badrequest(str(exc)) return TaskHandler.render(task)
def PUT(self, cluster_id): """:returns: JSONized Task object. :http: * 200 (task successfully executed) * 404 (cluster not found in db) * 400 (failed to execute task) """ cluster = self.get_object_or_404( Cluster, cluster_id, log_404=("warning", "Error: there is no cluster " "with id '{0}' in DB.".format(cluster_id)), ) if cluster.net_provider == "nova_network": net_serializer = NovaNetworkConfigurationSerializer elif cluster.net_provider == "neutron": net_serializer = NeutronNetworkConfigurationSerializer try: network_info = net_serializer.serialize_for_cluster(cluster) logger.info(u"Network info:\n{0}".format(json.dumps(network_info, indent=4))) task_manager = ApplyChangesTaskManager(cluster_id=cluster.id) task = task_manager.execute() except Exception as exc: logger.warn(u"ClusterChangesHandler: error while execution" " deploy task: {0}".format(str(exc))) raise web.badrequest(str(exc)) return TaskHandler.render(task)
def test_no_changes_no_cry(self): self.env.create( nodes_kwargs=[ {"status": "ready"} ] ) cluster_db = self.env.clusters[0] objects.Cluster.clear_pending_changes(cluster_db) manager = ApplyChangesTaskManager(cluster_db.id) self.assertRaises(errors.WrongNodeStatus, manager.execute)
def test_no_node_no_cry(self): cluster = self.env.create_cluster(api=True) cluster_id = cluster['id'] manager = ApplyChangesTaskManager(cluster_id) task = Task(name='provision', cluster_id=cluster_id) self.db.add(task) self.db.commit() rpc.receiver.NailgunReceiver.deploy_resp(nodes=[ {'uid': 666, 'id': 666, 'status': 'discover'} ], task_uuid=task.uuid) self.assertRaises(errors.WrongNodeStatus, manager.execute)
def test_fail_if_vips_for_cluster_are_not_unique(self): cluster_net_roles = self.cluster.release.network_roles_metadata cluster_net_roles[1]["properties"]["vip"].append({"name": "vip1"}) cluster_net_roles[0]["properties"]["vip"].append({"name": "vip1"}) self.db.flush() with self.assertRaises(errors.CheckBeforeDeploymentError) as exc: ApplyChangesTaskManager(self.cluster.id)\ .check_before_deployment(self.task) self.assertIn('Duplicate VIP names found in network configuration', exc.exception.message)
def test_check_vip_names_is_merged(self): cluster_net_roles = self.cluster.release.network_roles_metadata cluster_net_roles[0]["properties"]["vip"].append({ "name": "vip1", "namespace": "vip_ns1" }) plugin_net_roles = [copy.deepcopy(cluster_net_roles[0])] plugin_net_roles[0]["properties"]["vip"] = [{ "name": "vip1", "namespace": "vip_ns1" }] self.plugin.network_roles_metadata = plugin_net_roles self.db.flush() self.assertNotRaises( errors.CheckBeforeDeploymentError, ApplyChangesTaskManager(self.cluster.id) .check_before_deployment, self.task )
def test_fail_if_vips_cannot_be_merged(self): cluster_net_roles = self.cluster.release.network_roles_metadata cluster_net_roles[0]["properties"]["vip"].append({ "name": "vip1", "namespace": "vip_ns1" }) plugin_net_roles = [copy.deepcopy(cluster_net_roles[0])] plugin_net_roles[0]["properties"]["vip"] = [{ "name": "vip1", "namespace": "vip_ns2" }] self.plugin.network_roles_metadata = plugin_net_roles self.db.flush() with self.assertRaises(errors.CheckBeforeDeploymentError) as exc: ApplyChangesTaskManager(self.cluster.id)\ .check_before_deployment(self.task) self.assertIn( 'Cannot override existing network roles', exc.exception.message )