def test_run_scale_settings_wrongids_uninstall(self): _ctx = self._gen_ctx() client = self._gen_rest_client() delete_instance = Mock() delete_instance._node_instance.id = "a" delete_instance.modification = 'removed' _ctx._get_modification.removed.node_instances = [delete_instance] with patch( "cloudify_scalelist.workflows.get_rest_client", Mock(return_value=client) ): scale_settings = {'a': { 'instances': 0, 'removed_ids_include_hint': ['b']}} fake_uninstall_node_instances = Mock() with patch( "cloudify_scalelist.workflows.lifecycle." "uninstall_node_instances", fake_uninstall_node_instances ): with self.assertRaisesRegexp( Exception, "Instance 'a' not in proposed list \['b'\]." ): workflows._run_scale_settings(_ctx, scale_settings, {}, instances_remove_ids=['b']) fake_uninstall_node_instances.assert_not_called() _ctx.deployment.start_modification.assert_called_with( scale_settings ) _ctx._get_modification.rollback.assert_called_with() _ctx._get_modification.finish.assert_not_called()
def test_run_scale_settings_install_withtransacrtion_id(self): _ctx = self._gen_ctx() client = self._gen_rest_client() added_instance = Mock() added_instance._node_instance.id = "a" added_instance._node_instance.node_id = "type_a" added_instance.modification = 'added' related_instance = Mock() related_instance._node_instance.id = "f" related_instance._node_instance.node_id = "type_f" related_instance.modification = 'related' _ctx._get_modification.added.node_instances = [added_instance, related_instance] with patch( "cloudify_scalelist.workflows.get_rest_client", Mock(return_value=client) ): scale_settings = {'a': {'instances': 1}} fake_install_node_instances = Mock() with patch( "cloudify_scalelist.workflows.lifecycle." "install_node_instances", fake_install_node_instances ): fake_uninstall_instances = Mock(return_value=None) with patch( "cloudify_scalelist.workflows._uninstall_instances", fake_uninstall_instances ): fake_update_instances = Mock(return_value=None) with patch( "cloudify_scalelist.workflows." "_update_runtime_properties", fake_update_instances ): workflows._run_scale_settings( _ctx, scale_settings, {"type_a": [{"c": "f"}]}, scale_transaction_field='_transaction', scale_transaction_value='value' ) fake_update_instances.assert_called_with( _ctx, "a", {'c': 'f', '_transaction': 'value'}) fake_uninstall_instances.assert_not_called() fake_install_node_instances.assert_called_with( graph=_ctx.graph_mode(), node_instances=set([added_instance]), related_nodes=set([related_instance]) ) _ctx.deployment.start_modification.assert_called_with( scale_settings ) _ctx._get_modification.rollback.assert_not_called() _ctx._get_modification.finish.assert_called_with()
def test_run_scale_settings_install_failed(self): _ctx = self._gen_ctx() client = self._gen_rest_client() added_instance = Mock() added_instance._node_instance.id = "a" added_instance.modification = 'added' related_instance = Mock() related_instance._node_instance.id = "f" related_instance.modification = 'related' _ctx._get_modification.added.node_instances = [added_instance, related_instance] with patch( "cloudify_scalelist.workflows.get_rest_client", Mock(return_value=client) ): scale_settings = {'a': {'instances': 1}} fake_install_node_instances = Mock( side_effect=Exception('Failed install')) with patch( "cloudify_scalelist.workflows.lifecycle." "install_node_instances", fake_install_node_instances ): fake_uninstall_instances = Mock(return_value=None) with patch( "cloudify_scalelist.workflows._uninstall_instances", fake_uninstall_instances ): with self.assertRaisesRegexp( Exception, "Failed install" ): workflows._run_scale_settings( _ctx, scale_settings, {}, ignore_rollback_failure=False) fake_uninstall_instances.assert_called_with( _ctx, _ctx.graph_mode(), set([added_instance]), set([related_instance]), False) fake_install_node_instances.assert_called_with( graph=_ctx.graph_mode(), node_instances=set([added_instance]), related_nodes=set([related_instance]) ) _ctx.deployment.start_modification.assert_called_with( scale_settings ) _ctx._get_modification.rollback.assert_called_with() _ctx._get_modification.finish.assert_not_called()
def test_run_scale_settings(self): _ctx = self._gen_ctx() client = self._gen_rest_client() with patch( "cloudify_scalelist.workflows.get_rest_client", Mock(return_value=client) ): scale_settings = {'a': { 'instances': 0, 'removed_ids_include_hint': []}} # check run with empty instances list workflows._run_scale_settings(_ctx, scale_settings, {}) _ctx.deployment.start_modification.assert_called_with( scale_settings ) _ctx._get_modification.finish.assert_called_with()
def test_run_scale_settings_correct_uninstall(self): _ctx = self._gen_ctx() client = self._gen_rest_client() delete_instance = Mock() delete_instance._node_instance.id = "a" delete_instance.modification = 'removed' related_instance = Mock() related_instance._node_instance.id = "f" related_instance.modification = 'related' _ctx._get_modification.removed.node_instances = [delete_instance, related_instance] with patch( "cloudify_scalelist.workflows.get_rest_client", Mock(return_value=client) ): scale_settings = {'a': { 'instances': 0, 'removed_ids_include_hint': []}} fake_uninstall_node_instances = Mock() with patch( "cloudify_scalelist.workflows.lifecycle" ".uninstall_node_instances", fake_uninstall_node_instances ): workflows._run_scale_settings(_ctx, scale_settings, {}) fake_uninstall_node_instances.assert_called_with( graph=_ctx.graph_mode(), node_instances=set([delete_instance]), ignore_failure=False, related_nodes=set([related_instance]) ) _ctx.deployment.start_modification.assert_called_with( scale_settings ) _ctx._get_modification.finish.assert_called_with() _ctx._get_modification.rollback.assert_not_called()