Exemplo n.º 1
0
    def test_launch_stack(self):
        template = self.stack_templates.first()
        stack = self.stacks.first()
        self.mock_template_validate.return_value = \
            json.loads(template.validate)
        self.mock_stack_create.reutrn_value = None
        self.mock_network_list_for_tenant.side_effect = \
            [self.networks.list(), self.networks.list()]

        url = reverse('horizon:project:stacks:select_template')
        res = self.client.get(url)
        self.assertTemplateUsed(res, 'project/stacks/select_template.html')

        form_data = {
            'template_source': 'raw',
            'template_data': template.data,
            'referenced_files': {},
            'method': forms.TemplateForm.__name__
        }
        res = self.client.post(url, form_data)
        self.assertTemplateUsed(res, 'project/stacks/create.html')

        url = reverse('horizon:project:stacks:launch')
        form_data = {
            'template_source': 'raw',
            'template_data': template.data,
            'password': '******',
            'parameters': template.validate,
            'stack_name': stack.stack_name,
            "timeout_mins": 60,
            "disable_rollback": True,
            "__param_DBUsername": "******",
            "__param_LinuxDistribution": "F17",
            "__param_InstanceType": "m1.small",
            "__param_KeyName": "test",
            "__param_DBPassword": "******",
            "__param_DBRootPassword": "******",
            "__param_DBName": "wordpress",
            "__param_Network": self.networks.list()[0]['id'],
            'method': forms.CreateStackForm.__name__
        }
        res = self.client.post(url, form_data)
        self.assertRedirectsNoFollow(res, INDEX_URL)
        self.mock_template_validate.assert_called_once_with(
            test.IsHttpRequest(),
            files={},
            template=hc_format.parse(template.data))
        self.mock_stack_create.assert_called_once_with(
            test.IsHttpRequest(),
            stack_name=stack.stack_name,
            timeout_mins=60,
            disable_rollback=True,
            template=None,
            parameters=test.IsA(dict),
            password='******',
            files=None)
        self.mock_network_list_for_tenant.assert_has_calls([
            mock.call(test.IsHttpRequest(), self.tenant.id),
            mock.call(test.IsHttpRequest(), self.tenant.id)
        ])
Exemplo n.º 2
0
    def test_edit_stack_template(self):
        template = self.stack_templates.first()
        stack = self.stacks.first()

        self.mock_stack_get.return_value = stack
        self.mock_template_validate.return_value = \
            json.loads(template.validate)
        self.mock_stack_get.reutrn_value = stack
        self.mock_template_get.return_value = \
            json.loads(template.validate)

        fields = {
            'stack_name': stack.stack_name,
            'disable_rollback': True,
            'timeout_mins': 61,
            'password': '******',
            'template': None,
            'parameters': test.IsA(dict),
            'files': None
        }
        self.mock_stack_update.return_value = None
        self.mock_network_list_for_tenant.return_value = \
            self.networks.list()

        url = reverse('horizon:project:stacks:change_template',
                      args=[stack.id])
        res = self.client.get(url)
        self.assertTemplateUsed(res, 'project/stacks/change_template.html')

        form_data = {
            'template_source': 'raw',
            'template_data': template.data,
            'method': forms.ChangeTemplateForm.__name__
        }
        res = self.client.post(url, form_data)

        url = reverse('horizon:project:stacks:edit_stack', args=[
            stack.id,
        ])
        form_data = {
            'template_source': 'raw',
            'template_data': template.data,
            'password': '******',
            'parameters': template.validate,
            'stack_name': stack.stack_name,
            'stack_id': stack.id,
            "timeout_mins": 61,
            "disable_rollback": True,
            "__param_DBUsername": "******",
            "__param_LinuxDistribution": "F17",
            "__param_InstanceType": "m1.small",
            "__param_KeyName": "test",
            "__param_DBPassword": "******",
            "__param_DBRootPassword": "******",
            "__param_DBName": "wordpress",
            "__param_Network": self.networks.list()[0]['id'],
            'method': forms.EditStackForm.__name__
        }
        res = self.client.post(url, form_data)
        self.assertRedirectsNoFollow(res, INDEX_URL)
        self.mock_template_validate.assert_called_once_with(
            test.IsHttpRequest(),
            files={},
            template=hc_format.parse(template.data))
        self.mock_template_get.assert_called_once_with(test.IsHttpRequest(),
                                                       stack.id)
        self.mock_stack_update.assert_called_once_with(test.IsHttpRequest(),
                                                       stack_id=stack.id,
                                                       **fields)
        self.mock_network_list_for_tenant.assert_called_once_with(
            test.IsHttpRequest(), self.tenant.id)