def test_set_tls_parameters_ca_found_camap_provided(self):
        action = deployment.DeployStackAction(1,
                                              'overcloud',
                                              skip_deploy_identifier=True)
        my_params = {}
        my_env = {
            'parameter_defaults': {
                'CAMap': {
                    'overcloud-ca': {
                        'content': b'ANOTER FAKE CERT'
                    }
                }
            }
        }
        with tempfile.NamedTemporaryFile() as ca_file:
            # Write test data
            ca_file.write(b'FAKE CA CERT')
            ca_file.flush()

            # Test
            action.set_tls_parameters(parameters=my_params,
                                      env=my_env,
                                      local_ca_path=ca_file.name)
            self.assertIn('CAMap', my_params)
            self.assertIn('undercloud-ca', my_params['CAMap'])
            self.assertIn('content', my_params['CAMap']['undercloud-ca'])
            self.assertEqual(b'FAKE CA CERT',
                             my_params['CAMap']['undercloud-ca']['content'])
            self.assertIn('overcloud-ca', my_params['CAMap'])
            self.assertIn('content', my_params['CAMap']['overcloud-ca'])
            self.assertEqual(b'ANOTER FAKE CERT',
                             my_params['CAMap']['overcloud-ca']['content'])
    def test_run(self, mock_ctx, get_orchestration_client_mock,
                 mock_get_object_client, mock_get_workflow_client,
                 mock_get_template_contents,
                 mock_process_multiple_environments_and_files, mock_time):

        mock_ctx.return_value = mock.MagicMock()
        # setup swift
        swift = mock.MagicMock(url="http://test.com")
        swift.get_object.side_effect = swiftexceptions.ClientException(
            'atest2')
        mock_get_object_client.return_value = swift

        heat = mock.MagicMock()
        heat.stacks.get.return_value = None
        get_orchestration_client_mock.return_value = heat

        mock_mistral = mock.MagicMock()
        mock_env = mock.MagicMock()
        mock_env.variables = {
            'temp_environment': 'temp_environment',
            'template': 'template',
            'environments': [{
                u'path': u'environments/test.yaml'
            }],
            'parameter_defaults': {
                'random_existing_data': 'a_value'
            },
        }
        mock_mistral.environments.get.return_value = mock_env
        mock_get_workflow_client.return_value = mock_mistral

        mock_get_template_contents.return_value = ({}, {
            'heat_template_version':
            '2016-04-30'
        })
        mock_process_multiple_environments_and_files.return_value = ({}, {})

        # freeze time at datetime.datetime(2016, 9, 8, 16, 24, 24)
        mock_time.time.return_value = 1473366264

        action = deployment.DeployStackAction(1, 'overcloud')
        action.run()

        # verify parameters are as expected
        expected_defaults = {
            'DeployIdentifier': 1473366264,
            'StackAction': 'CREATE',
            'UpdateIdentifier': '',
            'random_existing_data': 'a_value'
        }
        self.assertEqual(expected_defaults,
                         mock_env.variables['parameter_defaults'])

        heat.stacks.create.assert_called_once_with(
            environment={},
            files={},
            stack_name='overcloud',
            template={'heat_template_version': '2016-04-30'},
            timeout_mins=1,
        )
 def test_set_tls_parameters_no_ca_found(self):
     action = deployment.DeployStackAction(1,
                                           'overcloud',
                                           skip_deploy_identifier=True)
     my_params = {}
     my_env = {'parameter_defaults': {}}
     action.set_tls_parameters(parameters=my_params,
                               env=my_env,
                               local_ca_path='/tmp/my-unexistent-file.txt')
     self.assertEqual(my_params, {})
Exemple #4
0
    def test_run_update_failed(self, get_orchestration_client_mock,
                               mock_get_object_client,
                               mock_get_template_contents,
                               mock_process_multiple_environments_and_files,
                               mock_time, mock_check_neutron_drivers):

        mock_ctx = mock.MagicMock()
        # setup swift
        swift = mock.MagicMock(url="http://test.com")
        mock_env = yaml.safe_dump(
            {
                'name': 'overcloud',
                'temp_environment': 'temp_environment',
                'template': 'template',
                'environments': [{
                    u'path': u'environments/test.yaml'
                }],
                'parameter_defaults': {
                    'random_existing_data': 'a_value'
                },
            },
            default_flow_style=False)
        swift.get_object.side_effect = (({}, mock_env), (
            {}, mock_env), swiftexceptions.ClientException('atest2'))
        mock_get_object_client.return_value = swift

        heat = mock.MagicMock()
        heat.stacks.get.return_value = mock.Mock()
        heat.stacks.update.side_effect = heat_exc.HTTPException("Oops")
        get_orchestration_client_mock.return_value = heat

        mock_get_template_contents.return_value = ({}, {
            'heat_template_version':
            '2016-04-30'
        })
        mock_process_multiple_environments_and_files.return_value = ({}, {})

        # freeze time at datetime.datetime(2016, 9, 8, 16, 24, 24)
        mock_time.time.return_value = 1473366264
        mock_check_neutron_drivers.return_value = None

        action = deployment.DeployStackAction(1, 'overcloud')
        expected = actions.Result(
            error="Error during stack update: ERROR: Oops\n")
        self.assertEqual(expected, action.run(mock_ctx))
    def test_run_skip_deploy_identifier(
            self, get_orchestration_client_mock, mock_get_object_client,
            mock_get_template_contents,
            mock_process_multiple_environments_and_files, mock_time):

        mock_ctx = mock.MagicMock()
        # setup swift
        swift = mock.MagicMock(url="http://test.com")
        mock_get_object_client.return_value = swift

        heat = mock.MagicMock()
        heat.stacks.get.return_value = None
        get_orchestration_client_mock.return_value = heat

        mock_env = yaml.safe_dump(
            {
                'name': constants.DEFAULT_CONTAINER_NAME,
                'temp_environment': 'temp_environment',
                'template': 'template',
                'environments': [{
                    u'path': u'environments/test.yaml'
                }],
                'parameter_defaults': {
                    'random_existing_data': 'a_value'
                },
            },
            default_flow_style=False)
        swift.get_object.side_effect = (({}, mock_env), (
            {}, mock_env), swiftexceptions.ClientException('atest2'))

        mock_get_template_contents.return_value = ({}, {
            'heat_template_version':
            '2016-04-30'
        })
        mock_process_multiple_environments_and_files.return_value = ({}, {})

        # freeze time at datetime.datetime(2016, 9, 8, 16, 24, 24)
        mock_time.time.return_value = 1473366264

        action = deployment.DeployStackAction(1,
                                              'overcloud',
                                              skip_deploy_identifier=True)
        action.run(mock_ctx)

        # verify parameters are as expected
        mock_env_updated = yaml.safe_dump(
            {
                'name': constants.DEFAULT_CONTAINER_NAME,
                'temp_environment': 'temp_environment',
                'parameter_defaults': {
                    'StackAction': 'CREATE',
                    'UpdateIdentifier': '',
                    'random_existing_data': 'a_value'
                },
                'template': 'template',
                'environments': [{
                    u'path': u'environments/test.yaml'
                }]
            },
            default_flow_style=False)

        swift.put_object.assert_called_once_with(
            constants.DEFAULT_CONTAINER_NAME, constants.PLAN_ENVIRONMENT,
            mock_env_updated)

        heat.stacks.create.assert_called_once_with(
            environment={},
            files={},
            stack_name='overcloud',
            template={'heat_template_version': '2016-04-30'},
            timeout_mins=1,
        )
        swift.delete_object.assert_called_once_with("overcloud-swift-rings",
                                                    "swift-rings.tar.gz")
        swift.copy_object.assert_called_once_with(
            "overcloud-swift-rings", "swift-rings.tar.gz",
            "overcloud-swift-rings/swift-rings.tar.gz-%d" % 1473366264)