コード例 #1
0
 def test_iter_default_chunk_size_64k(self):
     resp = fake_http.fake_httplib({},
                                   six.StringIO(
                                       'X' * (glance_http.CHUNKSIZE + 1)))
     iterator = glance_http.ResponseBodyIterator(resp)
     chunks = list(iterator)
     self.assertEqual(chunks, ['X' * glance_http.CHUNKSIZE, 'X'])
コード例 #2
0
 def _set_response_fixture(self, header, status, resp_body):
     resp = fake_http.fake_httplib(header, status=status,
                                   body=six.StringIO(resp_body))
     self.useFixture(mockpatch.PatchObject(httplib.HTTPConnection,
                     'getresponse',
                     return_value=resp))
     return resp
コード例 #3
0
 def _set_response_fixture(self, header, status, resp_body):
     resp = fake_http.fake_httplib(header,
                                   status=status,
                                   body=six.StringIO(resp_body))
     self.useFixture(
         mockpatch.PatchObject(httplib.HTTPConnection,
                               'getresponse',
                               return_value=resp))
     return resp
コード例 #4
0
 def test_iter_default_chunk_size_64k(self):
     resp = fake_http.fake_httplib({}, six.StringIO(
         'X' * (glance_http.CHUNKSIZE + 1)))
     iterator = glance_http.ResponseBodyIterator(resp)
     chunks = list(iterator)
     self.assertEqual(chunks, ['X' * glance_http.CHUNKSIZE, 'X'])
コード例 #5
0
    def test_network_cleanup(self, MockRestClient):
        def side_effect(**args):
            return {
                "security_groups": [
                    {
                        "tenant_id": args["tenant_id"],
                        "name": args["name"],
                        "description": args["name"],
                        "security_group_rules": [],
                        "id": "sg-%s" % args["tenant_id"],
                    }
                ]
            }

        iso_creds = isolated_creds.IsolatedCreds(name="test class")
        # Create primary tenant and network
        self._mock_assign_user_role()
        self._mock_list_role()
        self._mock_user_create("1234", "fake_prim_user")
        self._mock_tenant_create("1234", "fake_prim_tenant")
        self._mock_network_create(iso_creds, "1234", "fake_net")
        self._mock_subnet_create(iso_creds, "1234", "fake_subnet")
        self._mock_router_create("1234", "fake_router")
        router_interface_mock = self.patch(
            "tempest.services.network.json.network_client.NetworkClient." "add_router_interface_with_subnet_id"
        )
        iso_creds.get_primary_creds()
        router_interface_mock.called_once_with("1234", "1234")
        router_interface_mock.reset_mock()
        # Create alternate tenant and network
        self._mock_user_create("12345", "fake_alt_user")
        self._mock_tenant_create("12345", "fake_alt_tenant")
        self._mock_network_create(iso_creds, "12345", "fake_alt_net")
        self._mock_subnet_create(iso_creds, "12345", "fake_alt_subnet")
        self._mock_router_create("12345", "fake_alt_router")
        iso_creds.get_alt_creds()
        router_interface_mock.called_once_with("12345", "12345")
        router_interface_mock.reset_mock()
        # Create admin tenant and networks
        self._mock_user_create("123456", "fake_admin_user")
        self._mock_tenant_create("123456", "fake_admin_tenant")
        self._mock_network_create(iso_creds, "123456", "fake_admin_net")
        self._mock_subnet_create(iso_creds, "123456", "fake_admin_subnet")
        self._mock_router_create("123456", "fake_admin_router")
        self._mock_list_roles("123456", "admin")
        iso_creds.get_admin_creds()
        self.patch("tempest.services.identity.v2.json.identity_client." "IdentityClient.delete_user")
        self.patch("tempest.services.identity.v2.json.identity_client." "IdentityClient.delete_tenant")
        net = mock.patch.object(iso_creds.network_admin_client, "delete_network")
        net_mock = net.start()
        subnet = mock.patch.object(iso_creds.network_admin_client, "delete_subnet")
        subnet_mock = subnet.start()
        router = mock.patch.object(iso_creds.network_admin_client, "delete_router")
        router_mock = router.start()
        remove_router_interface_mock = self.patch(
            "tempest.services.network.json.network_client.NetworkClient." "remove_router_interface_with_subnet_id"
        )
        return_values = ({"status": 200}, {"ports": []})
        port_list_mock = mock.patch.object(iso_creds.network_admin_client, "list_ports", return_value=return_values)

        port_list_mock.start()
        secgroup_list_mock = mock.patch.object(
            iso_creds.network_admin_client, "list_security_groups", side_effect=side_effect
        )
        secgroup_list_mock.start()

        return_values = (fake_http.fake_httplib({}, status=204), {})
        remove_secgroup_mock = self.patch(
            "tempest.services.network.json.network_client." "NetworkClient.delete", return_value=return_values
        )
        iso_creds.clear_isolated_creds()
        # Verify default security group delete
        calls = remove_secgroup_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn("v2.0/security-groups/sg-1234", args)
        self.assertIn("v2.0/security-groups/sg-12345", args)
        self.assertIn("v2.0/security-groups/sg-123456", args)
        # Verify remove router interface calls
        calls = remove_router_interface_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1], calls)
        args = list(args)
        self.assertIn(("1234", "1234"), args)
        self.assertIn(("12345", "12345"), args)
        self.assertIn(("123456", "123456"), args)
        # Verify network delete calls
        calls = net_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn("1234", args)
        self.assertIn("12345", args)
        self.assertIn("123456", args)
        # Verify subnet delete calls
        calls = subnet_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn("1234", args)
        self.assertIn("12345", args)
        self.assertIn("123456", args)
        # Verify router delete calls
        calls = router_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn("1234", args)
        self.assertIn("12345", args)
        self.assertIn("123456", args)
コード例 #6
0
    def test_network_cleanup(self, MockRestClient):
        def side_effect(**args):
            return {"security_groups": [{"tenant_id": args['tenant_id'],
                                         "name": args['name'],
                                         "description": args['name'],
                                         "security_group_rules": [],
                                         "id": "sg-%s" % args['tenant_id']}]}
        creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)
        # Create primary tenant and network
        self._mock_assign_user_role()
        self._mock_list_role()
        self._mock_user_create('1234', 'fake_prim_user')
        self._mock_tenant_create('1234', 'fake_prim_tenant')
        self._mock_network_create(creds, '1234', 'fake_net')
        self._mock_subnet_create(creds, '1234', 'fake_subnet')
        self._mock_router_create('1234', 'fake_router')
        router_interface_mock = self.patch(
            'tempest.services.network.json.network_client.NetworkClient.'
            'add_router_interface_with_subnet_id')
        creds.get_primary_creds()
        router_interface_mock.called_once_with('1234', '1234')
        router_interface_mock.reset_mock()
        # Create alternate tenant and network
        self._mock_user_create('12345', 'fake_alt_user')
        self._mock_tenant_create('12345', 'fake_alt_tenant')
        self._mock_network_create(creds, '12345', 'fake_alt_net')
        self._mock_subnet_create(creds, '12345', 'fake_alt_subnet')
        self._mock_router_create('12345', 'fake_alt_router')
        creds.get_alt_creds()
        router_interface_mock.called_once_with('12345', '12345')
        router_interface_mock.reset_mock()
        # Create admin tenant and networks
        self._mock_user_create('123456', 'fake_admin_user')
        self._mock_tenant_create('123456', 'fake_admin_tenant')
        self._mock_network_create(creds, '123456', 'fake_admin_net')
        self._mock_subnet_create(creds, '123456', 'fake_admin_subnet')
        self._mock_router_create('123456', 'fake_admin_router')
        self._mock_list_roles('123456', 'admin')
        creds.get_admin_creds()
        self.patch('tempest.services.identity.v2.json.identity_client.'
                   'IdentityClient.delete_user')
        self.patch('tempest.services.identity.v2.json.identity_client.'
                   'IdentityClient.delete_tenant')
        net = mock.patch.object(creds.networks_admin_client,
                                'delete_network')
        net_mock = net.start()
        subnet = mock.patch.object(creds.subnets_admin_client,
                                   'delete_subnet')
        subnet_mock = subnet.start()
        router = mock.patch.object(creds.network_admin_client,
                                   'delete_router')
        router_mock = router.start()
        remove_router_interface_mock = self.patch(
            'tempest.services.network.json.network_client.NetworkClient.'
            'remove_router_interface_with_subnet_id')
        return_values = ({'status': 200}, {'ports': []})
        port_list_mock = mock.patch.object(creds.network_admin_client,
                                           'list_ports',
                                           return_value=return_values)

        port_list_mock.start()
        secgroup_list_mock = mock.patch.object(
            creds.network_admin_client,
            'list_security_groups',
            side_effect=side_effect)
        secgroup_list_mock.start()

        return_values = (fake_http.fake_httplib({}, status=204), {})
        remove_secgroup_mock = self.patch(
            'tempest.services.network.json.network_client.'
            'NetworkClient.delete', return_value=return_values)
        creds.clear_creds()
        # Verify default security group delete
        calls = remove_secgroup_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('v2.0/security-groups/sg-1234', args)
        self.assertIn('v2.0/security-groups/sg-12345', args)
        self.assertIn('v2.0/security-groups/sg-123456', args)
        # Verify remove router interface calls
        calls = remove_router_interface_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1], calls)
        args = list(args)
        self.assertIn(('1234', '1234'), args)
        self.assertIn(('12345', '12345'), args)
        self.assertIn(('123456', '123456'), args)
        # Verify network delete calls
        calls = net_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
        # Verify subnet delete calls
        calls = subnet_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
        # Verify router delete calls
        calls = router_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
コード例 #7
0
    def test_network_cleanup(self, MockRestClient):
        def side_effect(**args):
            return {
                "security_groups": [{
                    "tenant_id": args['tenant_id'],
                    "name": args['name'],
                    "description": args['name'],
                    "security_group_rules": [],
                    "id": "sg-%s" % args['tenant_id']
                }]
            }

        iso_creds = isolated_creds.IsolatedCreds(name='test class')
        # Create primary tenant and network
        self._mock_assign_user_role()
        self._mock_list_role()
        self._mock_user_create('1234', 'fake_prim_user')
        self._mock_tenant_create('1234', 'fake_prim_tenant')
        self._mock_network_create(iso_creds, '1234', 'fake_net')
        self._mock_subnet_create(iso_creds, '1234', 'fake_subnet')
        self._mock_router_create('1234', 'fake_router')
        router_interface_mock = self.patch(
            'tempest.services.network.json.network_client.NetworkClientJSON.'
            'add_router_interface_with_subnet_id')
        iso_creds.get_primary_creds()
        router_interface_mock.called_once_with('1234', '1234')
        router_interface_mock.reset_mock()
        # Create alternate tenant and network
        self._mock_user_create('12345', 'fake_alt_user')
        self._mock_tenant_create('12345', 'fake_alt_tenant')
        self._mock_network_create(iso_creds, '12345', 'fake_alt_net')
        self._mock_subnet_create(iso_creds, '12345', 'fake_alt_subnet')
        self._mock_router_create('12345', 'fake_alt_router')
        iso_creds.get_alt_creds()
        router_interface_mock.called_once_with('12345', '12345')
        router_interface_mock.reset_mock()
        # Create admin tenant and networks
        self._mock_user_create('123456', 'fake_admin_user')
        self._mock_tenant_create('123456', 'fake_admin_tenant')
        self._mock_network_create(iso_creds, '123456', 'fake_admin_net')
        self._mock_subnet_create(iso_creds, '123456', 'fake_admin_subnet')
        self._mock_router_create('123456', 'fake_admin_router')
        self._mock_list_roles('123456', 'admin')
        iso_creds.get_admin_creds()
        self.patch('tempest.services.identity.v2.json.identity_client.'
                   'IdentityClientJSON.delete_user')
        self.patch('tempest.services.identity.v2.json.identity_client.'
                   'IdentityClientJSON.delete_tenant')
        net = mock.patch.object(iso_creds.network_admin_client,
                                'delete_network')
        net_mock = net.start()
        subnet = mock.patch.object(iso_creds.network_admin_client,
                                   'delete_subnet')
        subnet_mock = subnet.start()
        router = mock.patch.object(iso_creds.network_admin_client,
                                   'delete_router')
        router_mock = router.start()
        remove_router_interface_mock = self.patch(
            'tempest.services.network.json.network_client.NetworkClientJSON.'
            'remove_router_interface_with_subnet_id')
        return_values = ({'status': 200}, {'ports': []})
        port_list_mock = mock.patch.object(iso_creds.network_admin_client,
                                           'list_ports',
                                           return_value=return_values)

        port_list_mock.start()
        secgroup_list_mock = mock.patch.object(iso_creds.network_admin_client,
                                               'list_security_groups',
                                               side_effect=side_effect)
        secgroup_list_mock.start()

        return_values = (fake_http.fake_httplib({}, status=204), {})
        remove_secgroup_mock = self.patch(
            'tempest.services.network.json.network_client.'
            'NetworkClientJSON.delete',
            return_value=return_values)
        iso_creds.clear_isolated_creds()
        # Verify default security group delete
        calls = remove_secgroup_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('v2.0/security-groups/sg-1234', args)
        self.assertIn('v2.0/security-groups/sg-12345', args)
        self.assertIn('v2.0/security-groups/sg-123456', args)
        # Verify remove router interface calls
        calls = remove_router_interface_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1], calls)
        args = list(args)
        self.assertIn(('1234', '1234'), args)
        self.assertIn(('12345', '12345'), args)
        self.assertIn(('123456', '123456'), args)
        # Verify network delete calls
        calls = net_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
        # Verify subnet delete calls
        calls = subnet_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
        # Verify router delete calls
        calls = router_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
コード例 #8
0
    def test_network_cleanup(self, MockRestClient):
        def side_effect(**args):
            return {
                "security_groups": [{
                    "tenant_id": args['tenant_id'],
                    "name": args['name'],
                    "description": args['name'],
                    "security_group_rules": [],
                    "id": "sg-%s" % args['tenant_id']
                }]
            }

        creds = dynamic_creds.DynamicCredentialProvider(**self.fixed_params)
        # Create primary tenant and network
        self._mock_assign_user_role()
        self._mock_list_role()
        self._mock_user_create('1234', 'fake_prim_user')
        self._mock_tenant_create('1234', 'fake_prim_tenant')
        self._mock_network_create(creds, '1234', 'fake_net')
        self._mock_subnet_create(creds, '1234', 'fake_subnet')
        self._mock_router_create('1234', 'fake_router')
        router_interface_mock = self.patch(
            'tempest.services.network.json.routers_client.RoutersClient.'
            'add_router_interface')
        creds.get_primary_creds()
        router_interface_mock.assert_called_once_with('1234', subnet_id='1234')
        router_interface_mock.reset_mock()
        # Create alternate tenant and network
        self._mock_user_create('12345', 'fake_alt_user')
        self._mock_tenant_create('12345', 'fake_alt_tenant')
        self._mock_network_create(creds, '12345', 'fake_alt_net')
        self._mock_subnet_create(creds, '12345', 'fake_alt_subnet')
        self._mock_router_create('12345', 'fake_alt_router')
        creds.get_alt_creds()
        router_interface_mock.assert_called_once_with('12345',
                                                      subnet_id='12345')
        router_interface_mock.reset_mock()
        # Create admin tenant and networks
        self._mock_user_create('123456', 'fake_admin_user')
        self._mock_tenant_create('123456', 'fake_admin_tenant')
        self._mock_network_create(creds, '123456', 'fake_admin_net')
        self._mock_subnet_create(creds, '123456', 'fake_admin_subnet')
        self._mock_router_create('123456', 'fake_admin_router')
        self._mock_list_roles('123456', 'admin')
        creds.get_admin_creds()
        self.patch('tempest.services.identity.v2.json.users_client.'
                   'UsersClient.delete_user')
        self.patch('tempest.services.identity.v2.json.tenants_client.'
                   'TenantsClient.delete_tenant')
        net = mock.patch.object(creds.networks_admin_client, 'delete_network')
        net_mock = net.start()
        subnet = mock.patch.object(creds.subnets_admin_client, 'delete_subnet')
        subnet_mock = subnet.start()
        router = mock.patch.object(creds.routers_admin_client, 'delete_router')
        router_mock = router.start()
        remove_router_interface_mock = self.patch(
            'tempest.services.network.json.routers_client.RoutersClient.'
            'remove_router_interface')
        return_values = ({'status': 200}, {'ports': []})
        port_list_mock = mock.patch.object(creds.ports_admin_client,
                                           'list_ports',
                                           return_value=return_values)

        port_list_mock.start()
        secgroup_list_mock = mock.patch.object(
            creds.security_groups_admin_client,
            'list_security_groups',
            side_effect=side_effect)
        secgroup_list_mock.start()

        return_values = (fake_http.fake_httplib({}, status=204), {})
        remove_secgroup_mock = self.patch(
            'tempest.lib.services.network.security_groups_client.'
            'SecurityGroupsClient.delete',
            return_value=return_values)
        creds.clear_creds()
        # Verify default security group delete
        calls = remove_secgroup_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('v2.0/security-groups/sg-1234', args)
        self.assertIn('v2.0/security-groups/sg-12345', args)
        self.assertIn('v2.0/security-groups/sg-123456', args)
        # Verify remove router interface calls
        calls = remove_router_interface_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: (x[1][0], x[2]), calls)
        args = list(args)
        self.assertIn(('1234', {'subnet_id': '1234'}), args)
        self.assertIn(('12345', {'subnet_id': '12345'}), args)
        self.assertIn(('123456', {'subnet_id': '123456'}), args)
        # Verify network delete calls
        calls = net_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
        # Verify subnet delete calls
        calls = subnet_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)
        # Verify router delete calls
        calls = router_mock.mock_calls
        self.assertEqual(len(calls), 3)
        args = map(lambda x: x[1][0], calls)
        args = list(args)
        self.assertIn('1234', args)
        self.assertIn('12345', args)
        self.assertIn('123456', args)