Beispiel #1
0
    def test_delete_ok(self):

        segment = self.masakari_segment.list()[0]
        data = {
            'object_ids': [segment.uuid],
            'action': 'failover_segment__delete'
        }
        with mock.patch(
                'masakaridashboard.api.api.get_segment_list',
                return_value=(self.masakari_segment.list(), True,
                              True)), mock.patch(
                                  'masakaridashboard.api.api.segment_delete',
                                  return_value=None) as mocked_delete:
            res = self.client.post(INDEX_URL, data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
        mocked_delete.assert_called_once_with(helpers.IsHttpRequest(),
                                              segment.uuid,
                                              ignore_missing=True)
Beispiel #2
0
    def test_network_create_without_physical_networks(self):
        tenants = self.tenants.list()
        self.mock_tenant_list.return_value = [tenants, False]
        self._stub_is_extension_supported({
            'provider': True,
            'network_availability_zone': False,
            'subnet_allocation': False
        })

        url = reverse('horizon:admin:networks:create')
        res = self.client.get(url)
        physical_network = res.context['form'].fields['physical_network']
        self.assertEqual(type(physical_network), forms.CharField)

        self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
        self._check_is_extension_supported({
            'provider': 1,
            'network_availability_zone': 2,
            'subnet_allocation': 1
        })
Beispiel #3
0
    def test_tenant_quota_usages_without_volume(self):
        tenant_id = self.request.user.tenant_id

        self._mock_service_enabled(volume_enabled=False)
        self.mock_tenant_absolute_limits.return_value = self.limits['absolute']

        quota_usages = quotas.tenant_quota_usages(self.request)
        expected_output = self.get_usages_from_limits(with_volume=False)

        # Compare internal structure of usages to expected.
        self.assertCountEqual(expected_output, quota_usages.usages)

        # Make sure that the `in` operator and the `.get()` method
        # behave as expected
        self.assertIn('ram', quota_usages)
        self.assertIsNotNone(quota_usages.get('ram'))

        self._check_service_enabled({'compute': 2, 'network': 1, 'volume': 1})
        self.mock_tenant_absolute_limits.assert_called_once_with(
            test.IsHttpRequest(), reserved=True, tenant_id=tenant_id)
Beispiel #4
0
    def test_subnet_create_post_network_exception(self, with_subnetpool=False):
        network = self.networks.first()
        subnet = self.subnets.first()
        self.mock_network_get.side_effect = self.exceptions.neutron

        form_data = {}
        if with_subnetpool:
            subnetpool = self.subnetpools.first()
            form_data['subnetpool'] = subnetpool.id
        form_data.update(form_data_subnet(subnet, allocation_pools=[]))

        url = reverse('horizon:project:networks:createsubnet',
                      args=[subnet.network_id])
        res = self.client.post(url, form_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, NETWORKS_INDEX_URL)

        self.mock_network_get.assert_called_once_with(
            test.IsHttpRequest(), network.id)
Beispiel #5
0
    def test_create_snapshot_post_exception(self, mock_snapshot_create):
        server = self.servers.first()
        snapshot = self.snapshots.first()

        mock_snapshot_create.side_effect = self.exceptions.nova

        formData = {
            'method': 'CreateSnapshot',
            'tenant_id': self.tenant.id,
            'instance_id': server.id,
            'name': snapshot.name
        }
        url = reverse('horizon:project:images:snapshots:create',
                      args=[server.id])
        res = self.client.post(url, formData)
        redirect = reverse("horizon:project:instances:index")

        self.assertRedirectsNoFollow(res, redirect)
        mock_snapshot_create.assert_called_once_with(test.IsHttpRequest(),
                                                     server.id, snapshot.name)
Beispiel #6
0
    def test_router_with_interface_delete(self):
        router = self.routers.first()
        ports = self.ports.list()
        tenants = self.tenants.list()
        quota_data = self.neutron_quota_usages.first()

        self.mock_router_list.return_value = self.routers.list()
        self.mock_tenant_list.return_value = [tenants, False]
        self._mock_external_network_list(count=3)
        self.mock_tenant_quota_usages.return_value = quota_data
        self.mock_is_extension_supported.return_value = True
        self.mock_port_list.return_value = ports
        self.mock_router_remove_interface.return_value = None
        self.mock_router_delete.return_value = None

        res = self.client.get(self.INDEX_URL)

        formData = {'action': 'routers__delete__' + router.id}
        res = self.client.post(self.INDEX_URL, formData, follow=True)
        self.assertNoFormErrors(res)
        self.assertMessageCount(response=res, success=1)
        self.assertIn('Deleted Router: ' + router.name,
                      res.content.decode('utf-8'))

        self.assert_mock_multiple_calls_with_same_arguments(
            self.mock_router_list, 3, mock.call(test.IsHttpRequest()))
        self.assert_mock_multiple_calls_with_same_arguments(
            self.mock_tenant_list, 3, mock.call(test.IsHttpRequest()))
        self._check_mock_external_network_list(count=3)
        self.assert_mock_multiple_calls_with_same_arguments(
            self.mock_tenant_quota_usages, 4,
            mock.call(test.IsHttpRequest(), targets=('router', )))
        self.assert_mock_multiple_calls_with_same_arguments(
            self.mock_is_extension_supported, 3,
            mock.call(test.IsHttpRequest(), 'router_availability_zone'))
        self.mock_port_list.assert_called_once_with(test.IsHttpRequest(),
                                                    device_id=router.id,
                                                    device_owner=mock.ANY)
        self.mock_router_remove_interface.assert_has_calls([
            mock.call(test.IsHttpRequest(), router.id, port_id=port.id)
            for port in ports
        ])
        self.mock_router_delete.assert_called_once_with(
            test.IsHttpRequest(), router.id)
Beispiel #7
0
    def test_add_rule_cidr_with_ipv6_disabled(self):
        sec_group = self.security_groups.first()
        self.mock_security_group_list.return_value = \
            self.security_groups.list()

        formData = {'method': 'AddRule',
                    'id': sec_group.id,
                    'rule_menu': 'custom',
                    'direction': 'ingress',
                    'port_or_range': 'port',
                    'ip_protocol': 37,
                    'cidr': 'fe80::/48',
                    'etherype': 'IPv4',
                    'remote': 'cidr'}
        res = self.client.post(self.edit_url, formData)
        self.assertFormError(res, 'form', 'cidr',
                             'Invalid version for IP address')
        self.assert_mock_multiple_calls_with_same_arguments(
            self.mock_security_group_list, 2,
            mock.call(test.IsHttpRequest()))
Beispiel #8
0
    def test_add_rule_ethertype_with_ipv6_disabled(self):
        self.mock_security_group_list.return_value = \
            self.security_groups.list()

        res = self.client.get(self.edit_url)

        self.assertIsInstance(
            res.context['form']['ethertype'].field.widget,
            forms.TextInput
        )
        self.assertIn(
            'readonly',
            res.context['form']['ethertype'].field.widget.attrs
        )
        self.assertEqual(
            res.context['form']['ethertype'].field.initial,
            'IPv4'
        )
        self.mock_security_group_list.assert_called_once_with(
            test.IsHttpRequest())
Beispiel #9
0
    def test_manage_qos_spec(self):
        qos_spec = self.cinder_qos_specs.first()
        index_url = reverse('horizon:admin:volume_types:qos_specs:index',
                            args=[qos_spec.id])

        self.mock_qos_spec_get.return_value = qos_spec

        res = self.client.get(index_url)

        self.assertTemplateUsed(res, 'admin/volume_types/qos_specs/index.html')
        rows = res.context['table'].get_rows()
        specs = self.cinder_qos_specs.first().specs
        for row in rows:
            key = row.cells['key'].data
            self.assertIn(key, specs)
            self.assertEqual(row.cells['value'].data, specs.get(key))

        self.mock_qos_spec_get.assert_has_calls(
            [mock.call(test.IsHttpRequest(), qos_spec.id)] * 2)
        self.assertEqual(2, self.mock_qos_spec_get.call_count)
Beispiel #10
0
    def test_import_keypair_invalid_key(self):
        key_name = "new_key_pair"
        public_key = "ABCDEF"
        key_type = "ssh"

        self.mock_keypair_import.side_effect = self.exceptions.nova

        formData = {
            'method': 'ImportKeypair',
            'name': key_name,
            'public_key': public_key,
            'key_type': key_type
        }
        url = reverse('horizon:project:key_pairs:import')
        res = self.client.post(url, formData, follow=True)
        self.assertEqual(res.redirect_chain, [])
        msg = 'Unable to import key pair.'
        self.assertFormErrors(res, count=1, message=msg)

        self.mock_keypair_import.assert_called_once_with(
            test.IsHttpRequest(), key_name, public_key, key_type)
Beispiel #11
0
    def _test_port_delete(self, mac_learning=False):
        port = self.ports.first()
        network_id = port.network_id
        self.mock_port_list.return_value = self.ports.list()
        self._stub_is_extension_supported({
            'network-ip-availability': True,
            'mac-learning': mac_learning
        })

        form_data = {'action': 'ports__delete__%s' % port.id}
        url = reverse(NETWORKS_DETAIL_URL, args=[network_id])
        res = self.client.post(url, form_data)

        self.assertRedirectsNoFollow(res, url)

        self.mock_port_list.assert_called_once_with(test.IsHttpRequest(),
                                                    network_id=network_id)
        self._check_is_extension_supported({
            'network-ip-availability': 1,
            'mac-learning': 1
        })
Beispiel #12
0
    def test_extra_create_post(self):
        vol_type = self.cinder_volume_types.first()
        create_url = reverse(
            'horizon:admin:volume_types:extras:create',
            args=[vol_type.id])
        index_url = reverse(
            'horizon:admin:volume_types:extras:index',
            args=[vol_type.id])

        data = {'key': 'k1',
                'value': 'v1'}

        self.mock_volume_type_extra_set.return_value = None
        resp = self.client.post(create_url, data)
        self.assertNoFormErrors(resp)
        self.assertMessageCount(success=1)
        self.assertRedirectsNoFollow(resp, index_url)
        self.mock_volume_type_extra_set.assert_called_once_with(
            test.IsHttpRequest(),
            vol_type.id,
            {data['key']: data['value']})
Beispiel #13
0
    def test_create(self):
        idp = self.identity_providers.first()

        self.mock_identity_provider_create.return_value = idp

        formData = {'method': 'RegisterIdPForm',
                    'id': idp.id,
                    'description': idp.description,
                    'enabled': idp.enabled,
                    'remote_ids': ', '.join(idp.remote_ids)}
        res = self.client.post(IDPS_REGISTER_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(success=1)

        self.mock_identity_provider_create.assert_called_once_with(
            test.IsHttpRequest(),
            idp.id,
            description=idp.description,
            enabled=idp.enabled,
            remote_ids=idp.remote_ids)
Beispiel #14
0
    def test_detail_add_rule_invalid_port(self):
        sec_group = self.security_groups.first()
        sec_group_list = self.security_groups.list()
        rule = self.security_group_rules.first()

        self.mock_security_group_list.return_value = sec_group_list

        formData = {'method': 'AddRule',
                    'id': sec_group.id,
                    'port_or_range': 'port',
                    'port': -1,
                    'rule_menu': rule.ip_protocol,
                    'cidr': rule.ip_range['cidr'],
                    'remote': 'cidr'}
        res = self.client.post(self.edit_url, formData)
        self.assertNoMessages()
        self.assertContains(res, "Not a valid port number")

        self.assert_mock_multiple_calls_with_same_arguments(
            self.mock_security_group_list, 2,
            mock.call(test.IsHttpRequest()))
Beispiel #15
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        self.mock_user_get.return_value = user

        formData = {
            'method': 'ChangePasswordForm',
            'id': user.id,
            'name': user.name,
            'password': '******',
            'confirm_password': '******'
        }

        res = self.client.post(USER_CHANGE_PASSWORD_URL, formData)

        self.assertFormError(res, "form", 'password',
                             ['Password must be between 8 and 18 characters.'])

        self.mock_user_get.assert_called_once_with(test.IsHttpRequest(),
                                                   '1',
                                                   admin=False)
Beispiel #16
0
    def test_import_keypair_with_regex_defined_name(self):
        key1_name = "new-key-pair with_regex"
        public_key = "ssh-rsa ABCDEFGHIJKLMNOPQR\r\n" \
                     "STUVWXYZ1234567890\r" \
                     "XXYYZZ user@computer\n\n"
        key_type = "ssh"
        self.mock_keypair_import.return_value = None

        formData = {
            'method': 'ImportKeypair',
            'name': key1_name,
            'public_key': public_key,
            'key_type': key_type
        }
        url = reverse('horizon:project:key_pairs:import')
        res = self.client.post(url, formData)
        self.assertMessageCount(res, success=1)

        self.mock_keypair_import.assert_called_once_with(
            test.IsHttpRequest(), key1_name,
            public_key.replace("\r", "").replace("\n", ""), key_type)
Beispiel #17
0
    def test_snapshot_actions(self):
        snapshots = self.snapshots.list()
        self.mock_image_list.return_value = [snapshots, False, False]

        res = self.client.get(INDEX_URL)
        self.assertTemplateUsed(res, INDEX_TEMPLATE)
        self.assertIn('images_table', res.context)
        snaps = res.context['images_table']
        self.assertEqual(len(snaps.get_rows()), 3)

        row_actions = snaps.get_row_actions(snaps.data[0])

        # first instance - status active, owned
        self.assertEqual(len(row_actions), 5)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")
        self.assertEqual(row_actions[1].verbose_name, u"Create Volume")
        self.assertEqual(row_actions[2].verbose_name, u"Edit Image")
        self.assertEqual(row_actions[3].verbose_name, u"Update Metadata")
        self.assertEqual(row_actions[4].verbose_name, u"Delete Image")

        row_actions = snaps.get_row_actions(snaps.data[1])

        # second instance - status active, not owned
        self.assertEqual(len(row_actions), 2)
        self.assertEqual(row_actions[0].verbose_name, u"Launch")
        self.assertEqual(row_actions[1].verbose_name, u"Create Volume")

        row_actions = snaps.get_row_actions(snaps.data[2])
        # third instance - status queued, only delete is available
        self.assertEqual(len(row_actions), 1)
        self.assertEqual(six.text_type(row_actions[0].verbose_name),
                         u"Delete Image")
        self.assertEqual(str(row_actions[0]), "<DeleteImage: delete>")

        self.mock_image_list.assert_called_once_with(test.IsHttpRequest(),
                                                     marker=None,
                                                     paginate=True,
                                                     sort_dir='asc',
                                                     sort_key='name',
                                                     reversed_order=False)
Beispiel #18
0
    def test_index_network_list_exception(self):
        self.mock_network_list.side_effect = self.exceptions.neutron
        self._stub_is_extension_supported({
            'network_availability_zone': True,
            'dhcp_agent_scheduler': True
        })

        res = self.client.get(INDEX_URL)

        self.assertTemplateUsed(res, INDEX_TEMPLATE)
        self.assertEqual(len(res.context['networks_table'].data), 0)
        self.assertMessageCount(res, error=1)

        self.mock_network_list.assert_called_once_with(test.IsHttpRequest(),
                                                       single_page=True,
                                                       limit=21,
                                                       sort_dir='asc',
                                                       sort_key='id')
        self._check_is_extension_supported({
            'network_availability_zone': 1,
            'dhcp_agent_scheduler': 1
        })
Beispiel #19
0
    def test_delete_availability(self, mock_metadefs_namespace_list):
        mock_metadefs_namespace_list.return_value = (self.metadata_defs.list(),
                                                     False, False)

        res = self.client.get(reverse(constants.METADATA_INDEX_URL))
        self.assertIn('namespaces_table', res.context)
        ns_table = res.context['namespaces_table']
        namespaces = ns_table.data

        for i in [1, 2]:
            row_actions = ns_table.get_row_actions(namespaces[i])
            self.assertEqual(len(row_actions), 3)
            self.assertIn('delete', [a.name for a in row_actions])
            self.assertIn('manage_resource_types',
                          [a.name for a in row_actions])

        mock_metadefs_namespace_list.assert_called_once_with(
            test.IsHttpRequest(),
            sort_dir='asc',
            marker=None,
            paginate=True,
            filters={})
Beispiel #20
0
    def test_create_with_domain(self):
        domain = self.domains.get(id="3")
        group = self.groups.get(id="1")

        self.setSessionValues(domain_context=domain.id,
                              domain_context_name=domain.name)

        self.mock_group_create.return_value = group

        formData = {'method': 'CreateGroupForm',
                    'name': group.name,
                    'description': group.description}
        res = self.client.post(GROUP_CREATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(success=1)

        self.mock_group_create.assert_called_once_with(
            test.IsHttpRequest(),
            description=group.description,
            domain_id=domain.id,
            name=group.name)
Beispiel #21
0
    def test_add_endpointgroup_get(self):
        networks = [
            {
                'subnets': [
                    self.subnets.first(),
                ]
            },
        ]

        self.mock_network_list_for_tenant.return_value = networks

        res = self.client.get(reverse(self.ADDENDPOINTGROUP_PATH))

        workflow = res.context['workflow']
        self.assertTemplateUsed(res, views.WorkflowView.template_name)
        self.assertEqual(workflow.name, workflows.AddEndpointGroup.name)

        expected_objs = [
            '<AddEndpointGroupStep: addendpointgroupaction>',
        ]
        self.assertQuerysetEqual(workflow.steps, expected_objs)
        self.mock_network_list_for_tenant.assert_called_once_with(
            helpers.IsHttpRequest(), self.tenant.id)
Beispiel #22
0
    def _test_image_detail_custom_props_get(self, image, mock_image_get):
        mock_image_get.return_value = image

        res = self.client.get(
            reverse('horizon:project:images:images:detail', args=[image.id]))

        image_props = res.context['image_props']

        # Test description property not displayed
        image_keys = [prop[0] for prop in image_props]
        self.assertNotIn(('description'), image_keys)

        # Test custom properties are sorted
        self.assertLess(image_props.index(('bar', 'bar', 'bar val')),
                        image_props.index(('foo', 'foo', 'foo val')))

        # Test all custom properties appear in template
        self.assertContains(res, '<dt title="bar">bar</dt>')
        self.assertContains(res, '<dd>bar val</dd>')
        self.assertContains(res, '<dt title="foo">foo</dt>')
        self.assertContains(res, '<dd>foo val</dd>')

        mock_image_get.assert_called_once_with(test.IsHttpRequest(), image.id)
Beispiel #23
0
    def test_admin_metadata_defs_create_namespace_post(
            self, mock_metadefs_namespace_create):
        metadata = {
            "namespace": "test_namespace",
            "display_name": "display_name",
            "description": "description",
            "visibility": "private",
            "protected": False,
        }

        mock_metadefs_namespace_create.return_value = metadata

        form_data = {
            'source_type': 'raw',
            'direct_input': json.dumps(metadata)
        }

        res = self.client.post(reverse(constants.METADATA_CREATE_URL),
                               form_data)

        self.assertNoFormErrors(res)
        mock_metadefs_namespace_create.assert_called_once_with(
            test.IsHttpRequest(), metadata)
Beispiel #24
0
    def test_failing_nova_call_post(self):
        hypervisor = self.hypervisors.list().pop().hypervisor_hostname
        services = [service for service in self.services.list()
                    if service.binary == 'nova-compute']

        self.mock_service_disable.side_effect = self.exceptions.nova

        url = reverse('horizon:admin:hypervisors:compute:disable_service',
                      args=[hypervisor])

        form_data = {'host': services[0].host,
                     'reason': 'test disable'}

        res = self.client.post(url, form_data)
        dest_url = reverse('horizon:admin:hypervisors:index')
        self.assertMessageCount(error=1)
        self.assertRedirectsNoFollow(res, dest_url)

        self.mock_service_disable.assert_called_once_with(
            test.IsHttpRequest(),
            services[0].host,
            'nova-compute',
            reason='test disable')
Beispiel #25
0
    def test_create_group_exception(self):
        group = self.cinder_groups.first()
        volume_types = self.cinder_volume_types.list()
        volume_type_id = self.cinder_volume_types.first().id
        selected_types = [volume_type_id]
        az = self.cinder_availability_zones.first().zoneName
        formData = {
            'volume_types': '1',
            'name': 'test VG',
            'description': 'test desc',
            'availability_zone': az,
            'group_type': group.group_type,
            'add_vtypes_to_group_role_member': selected_types,
        }

        self.mock_extension_supported.return_value = True
        self.mock_availability_zone_list.return_value = \
            self.cinder_availability_zones.list()
        self.mock_volume_type_list.return_value = volume_types
        self.mock_group_list.return_value = self.cinder_groups.list()
        self.mock_group_type_list.return_value = self.cinder_group_types.list()
        self.mock_group_create.side_effect = self.exceptions.cinder

        url = reverse('horizon:project:volume_groups:create')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
        self.assertIn("Unable to create group.",
                      res.cookies.output())

        self.mock_extension_supported.assert_called_once_with(
            test.IsHttpRequest(), 'AvailabilityZones')
        self.mock_availability_zone_list.assert_called_once_with(
            test.IsHttpRequest())
        self.mock_volume_type_list.assert_called_once_with(
            test.IsHttpRequest())
        self.mock_group_list.assert_called_once_with(test.IsHttpRequest())
        self.mock_group_type_list.assert_called_once_with(test.IsHttpRequest())
        self.mock_group_create.assert_called_once_with(
            test.IsHttpRequest(),
            formData['name'],
            formData['group_type'],
            selected_types,
            description=formData['description'],
            availability_zone=formData['availability_zone'])
Beispiel #26
0
    def test_ajax_loading_instances(self):
        server = self.servers.first()
        self.mock_server_get.return_value = server
        self.mock_extension_supported.return_value = True
        self.mock_flavor_get.return_value = self.flavors.first()
        self.mock_tenant_get.return_value = self.tenants.first()
        self.mock_servers_update_addresses.return_value = None

        url = (INDEX_URL + "?action=row_update&table=instances&obj_id=" +
               server.id)

        res = self.client.get(url, {}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        self.assertTemplateUsed(res, "horizon/common/_data_table_row.html")
        self.assertContains(res, "test_tenant", 1, 200)
        self.assertContains(res, "instance-host", 1, 200)
        # two instances of name, other name comes from row data-display
        self.assertContains(res, "server_1", 2, 200)
        self.assertContains(res, "10.0.0.1", 1, 200)
        self.assertContains(res, "RAM</th><td>512MB", 1, 200)
        self.assertContains(res, "VCPUs</th><td>1", 1, 200)
        self.assertContains(res, "Size</th><td>0 GB", 1, 200)
        self.assertContains(res, "Active", 1, 200)
        self.assertContains(res, "Running", 1, 200)

        self.mock_server_get.assert_called_once_with(test.IsHttpRequest(),
                                                     server.id)
        self.mock_extension_supported.assert_has_calls([
            mock.call('AdminActions', test.IsHttpRequest()),
            mock.call('AdminActions', test.IsHttpRequest()),
            mock.call('Shelve', test.IsHttpRequest())
        ])
        self.assertEqual(3, self.mock_extension_supported.call_count)
        self.mock_flavor_get.assert_called_once_with(test.IsHttpRequest(),
                                                     server.flavor['id'])
        self.mock_tenant_get.assert_called_once_with(test.IsHttpRequest(),
                                                     server.tenant_id,
                                                     admin=True)
        self.mock_servers_update_addresses.assert_called_once_with(
            test.IsHttpRequest(), [server])
Beispiel #27
0
    def test_create_cgroup(self):
        cgroup = self.cinder_consistencygroups.first()
        volume_types = self.cinder_volume_types.list()
        volume_type_id = self.cinder_volume_types.first().id
        az = self.cinder_availability_zones.first().zoneName
        formData = {
            'volume_types': '1',
            'name': 'test CG',
            'description': 'test desc',
            'availability_zone': az,
            'add_vtypes_to_cgroup_role_member': [volume_type_id]
        }

        self.mock_extension_supported.return_value = True
        self.mock_availability_zone_list.return_value = \
            self.cinder_availability_zones.list()
        self.mock_volume_type_list.return_value = volume_types
        self.mock_volume_type_list_with_qos_associations.return_value = \
            volume_types
        self.mock_volume_cgroup_list.return_value = \
            self.cinder_consistencygroups.list()
        self.mock_volume_cgroup_create.return_value = cgroup

        url = reverse('horizon:project:cgroups:create')
        res = self.client.post(url, formData)
        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)

        self.mock_extension_supported.assert_called_once_with(
            test.IsHttpRequest(), 'AvailabilityZones')
        self.mock_availability_zone_list.assert_called_once_with(
            test.IsHttpRequest())
        self.mock_volume_type_list.assert_called_once_with(
            test.IsHttpRequest())
        self.mock_volume_type_list_with_qos_associations \
            .assert_called_once_with(test.IsHttpRequest())
        self.mock_volume_cgroup_list.assert_called_once_with(
            test.IsHttpRequest())
        self.mock_volume_cgroup_create.assert_called_once_with(
            test.IsHttpRequest(),
            formData['volume_types'],
            formData['name'],
            description=formData['description'],
            availability_zone=formData['availability_zone'])
Beispiel #28
0
    def test_add_rule_post_dest_None(self):
        rule1 = self.fw_rules.first()
        form_data = {'name': rule1.name,
                     'description': rule1.description,
                     'protocol': rule1.protocol,
                     'action': rule1.action,
                     'source_ip_address': rule1.source_ip_address,
                     'source_port': rule1.source_port,
                     'shared': rule1.shared,
                     'enabled': rule1.enabled,
                     'ip_version': rule1.ip_version
                     }

        self.mock_rule_create.return_value = rule1

        res = self.client.post(reverse(self.ADDRULE_PATH), form_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
        data = form_data.copy()
        data['destination_ip_address'] = None
        data['destination_port'] = None
        self.mock_rule_create.assert_called_once_with(
            helpers.IsHttpRequest(), **data)
Beispiel #29
0
    def test_networks_list_with_non_exist_tenant_filter(self):
        self._stub_is_extension_supported({
            'network_availability_zone': True,
            'dhcp_agent_scheduler': True
        })
        self.mock_tenant_list.return_value = [self.tenants.list(), False]

        self.client.post(reverse('horizon:admin:networks:index'),
                         data={
                             'networks__filter_admin_networks__q_field':
                             'project',
                             'networks__filter_admin_networks__q':
                             'non_exist_tenant'
                         })
        res = self.client.get(reverse('horizon:admin:networks:index'))
        self.assertTemplateUsed(res, INDEX_TEMPLATE)
        networks = res.context['networks_table'].data
        self.assertCountEqual(networks, [])

        self._check_is_extension_supported({
            'network_availability_zone': 2,
            'dhcp_agent_scheduler': 2
        })
        self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
Beispiel #30
0
    def test_index_with_domain(self):
        domain = self.domains.get(id="1")
        filters = {}
        self.setSessionValues(domain_context=domain.id,
                              domain_context_name=domain.name)
        groups = self._get_groups(domain.id)

        self.mock_group_list.return_value = groups

        res = self.client.get(GROUPS_INDEX_URL)

        self.assertTemplateUsed(res, constants.GROUPS_INDEX_VIEW_TEMPLATE)
        self.assertCountEqual(res.context['table'].data, groups)
        if domain.id:
            for group in res.context['table'].data:
                self.assertCountEqual(group.domain_id, domain.id)

        self.assertContains(res, 'Create Group')
        self.assertContains(res, 'Edit')
        self.assertContains(res, 'Delete Group')

        self.mock_group_list.assert_called_once_with(test.IsHttpRequest(),
                                                     domain=domain.id,
                                                     filters=filters)