Example #1
0
    def test_run(self, get_workflow_client_mock, get_orchestration_client,
                 get_obj_client_mock):

        # setup swift
        swift = mock.MagicMock()
        swift.get_account.return_value = ({}, [
            {
                'name': self.container_name
            },
            {
                'name': 'test'
            },
        ])
        swift.get_container.return_value = ({
            'x-container-meta-usage-tripleo':
            'plan'
        }, [{
            'name': 'some-name.yaml'
        }, {
            'name': 'some-other-name.yaml'
        }, {
            'name': 'yet-some-other-name.yaml'
        }, {
            'name': 'finally-another-name.yaml'
        }])

        get_obj_client_mock.return_value = swift

        # setup mistral
        mistral = mock.MagicMock()
        mistral_environment = mock.Mock()
        mistral_environment.name = self.container_name
        mistral.environments.list.return_value = [
            mistral_environment,
        ]
        get_workflow_client_mock.return_value = mistral

        # setup heat
        heat = mock.MagicMock()
        heat.stacks.get = mock.Mock(side_effect=heatexceptions.HTTPNotFound)
        get_orchestration_client.return_value = heat

        action = plan.DeletePlanAction(self.container_name)
        action.run()

        mock_calls = [
            mock.call('overcloud', 'some-name.yaml'),
            mock.call('overcloud', 'some-other-name.yaml'),
            mock.call('overcloud', 'yet-some-other-name.yaml'),
            mock.call('overcloud', 'finally-another-name.yaml')
        ]
        swift.delete_object.assert_has_calls(mock_calls, any_order=True)

        swift.delete_container.assert_called_with(self.container_name)

        mistral.environments.delete.assert_called_with(self.container_name)
Example #2
0
    def test_run_stack_exists(self, get_orchestration_client):

        # setup heat
        heat = mock.MagicMock()
        heat.stacks.get.return_value = self.stack
        get_orchestration_client.return_value = heat

        # test that stack exists
        action = plan.DeletePlanAction(self.container_name)
        self.assertRaises(exception.StackInUseError, action.run)
        heat.stacks.get.assert_called_with(self.container_name)
def delete_deployment_plan(clients, container):
    """Delete a deployment plan.

    :param clients: Application client object.
    :type clients: Object

    :param container: Container name to pull from.
    :type container: String
    """

    context = clients.tripleoclient.create_mistral_context()
    result = plan.DeletePlanAction(container=container).run(context=context)
    # The action returns None if there are no errors.
    if result:
        raise RuntimeError(result)