def test_create_default_plan_existing(self):
        mock_mistral = mock.Mock()
        environment = collections.namedtuple('environment', ['name'])
        mock_mistral.environments.list.return_value = [
            environment(name='overcloud')
        ]

        undercloud._create_default_plan(mock_mistral)
        mock_mistral.executions.create.assert_not_called()
    def test_create_default_plan_existing(self):
        mock_mistral = mock.Mock()
        environment = collections.namedtuple('environment', ['name'])
        mock_mistral.environments.list.return_value = [
            environment(name='overcloud')
        ]

        undercloud._create_default_plan(mock_mistral)
        mock_mistral.executions.create.assert_not_called()
    def test_create_default_plan_failed(self):
        mock_mistral = mock.Mock()
        mock_mistral.environments.list.return_value = []
        mock_mistral.executions.get.return_value = mock.Mock(state="ERROR")

        # TODO(dmatthews): Switch to this check after this lands:
        #   https://review.openstack.org/#/c/371347/
        # self.assertRaises(
        #     RuntimeError,
        #     undercloud._create_default_plan, mock_mistral)
        undercloud._create_default_plan(mock_mistral)
    def test_create_default_plan_failed(self):
        mock_mistral = mock.Mock()
        mock_mistral.environments.list.return_value = []
        mock_mistral.executions.get.return_value = mock.Mock(state="ERROR")

        # TODO(dmatthews): Switch to this check after this lands:
        #   https://review.openstack.org/#/c/371347/
        # self.assertRaises(
        #     RuntimeError,
        #     undercloud._create_default_plan, mock_mistral)
        undercloud._create_default_plan(mock_mistral)
    def test_create_default_plan(self):
        mock_mistral = mock.Mock()
        mock_mistral.environments.list.return_value = []
        mock_mistral.executions.get.return_value = mock.Mock(state="SUCCESS")

        undercloud._create_default_plan(mock_mistral)
        mock_mistral.executions.create.assert_called_once_with(
            'tripleo.plan_management.v1.create_default_deployment_plan',
            workflow_input={
                'container': 'overcloud',
                'queue_name': mock.ANY
            })
    def test_create_default_plan(self):
        mock_mistral = mock.Mock()
        mock_mistral.environments.list.return_value = []
        mock_mistral.executions.get.return_value = mock.Mock(state="SUCCESS")

        undercloud._create_default_plan(mock_mistral)
        mock_mistral.executions.create.assert_called_once_with(
            'tripleo.plan_management.v1.create_default_deployment_plan',
            workflow_input={
                'container': 'overcloud',
                'queue_name': mock.ANY
            }
        )