def post_os_security_groups(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     assert list(body) == ['security_group']
     fakes.assert_has_keys(body['security_group'],
                           required=['name', 'description'])
     r = jsonutils.dumps({'security_group': security_group_1})
     return 202, headers, r
Exemplo n.º 2
0
 def post_os_security_groups(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     assert list(body) == ['security_group']
     fakes.assert_has_keys(body['security_group'],
                           required=['name', 'description'])
     r = jsonutils.dumps({'security_group': security_group_1})
     return 202, headers, r
Exemplo n.º 3
0
 def test_rebuild_server_preserve_ephemeral(self):
     s = self.cs.servers.get(1234)
     s.rebuild(image=1, preserve_ephemeral=True)
     self.assert_called('POST', '/servers/1234/action')
     body = jsonutils.loads(self.requests.last_request.body)
     d = body['rebuild']
     self.assertIn('preserve_ephemeral', d)
     self.assertEqual(True, d['preserve_ephemeral'])
Exemplo n.º 4
0
        def post_rules(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            assert list(body) == ['security_group_rule']
            fakes.assert_has_keys(body['security_group_rule'],
                                  required=['parent_group_id'],
                                  optional=['group_id', 'ip_protocol',
                                            'from_port', 'to_port', 'cidr'])

            return 202, headers, jsonutils.dumps({'security_group_rule': rule})
        def post_rules(request, context):
            body = jsonutils.loads(request.body)
            assert list(body) == ['security_group_rule']
            fakes.assert_has_keys(body['security_group_rule'],
                                  required=['parent_group_id'],
                                  optional=['group_id', 'ip_protocol',
                                            'from_port', 'to_port', 'cidr'])

            return {'security_group_rule': rule}
Exemplo n.º 6
0
 def test_rebuild_server_name_meta_files(self):
     files = {'/etc/passwd': 'some data'}
     s = self.cs.servers.get(1234)
     s.rebuild(image=1, name='new', meta={'foo': 'bar'}, files=files)
     body = jsonutils.loads(self.requests.last_request.body)
     d = body['rebuild']
     self.assertEqual('new', d['name'])
     self.assertEqual({'foo': 'bar'}, d['metadata'])
     self.assertEqual('/etc/passwd',
                      d['personality'][0]['path'])
Exemplo n.º 7
0
        def put_os_floating_ip_dns_testdomain(request, context):
            body = jsonutils.loads(request.body)
            if body["domain_entry"]["scope"] == "private":
                fakes.assert_has_keys(body["domain_entry"], required=["availability_zone", "scope"])
            elif body["domain_entry"]["scope"] == "public":
                fakes.assert_has_keys(body["domain_entry"], required=["project", "scope"])
            else:
                fakes.assert_has_keys(body["domain_entry"], required=["project", "scope"])

            return request.body
Exemplo n.º 8
0
        def post_rules(request, context):
            body = jsonutils.loads(request.body)
            assert list(body) == ['security_group_rule']
            fakes.assert_has_keys(body['security_group_rule'],
                                  required=['parent_group_id'],
                                  optional=[
                                      'group_id', 'ip_protocol', 'from_port',
                                      'to_port', 'cidr'
                                  ])

            return {'security_group_rule': rule}
Exemplo n.º 9
0
    def assert_called(self, method, path, body=None):
        self.assertEqual(httpretty.last_request().method, method)
        self.assertEqual(httpretty.last_request().path, path)

        if body:
            req_data = httpretty.last_request().body
            if isinstance(req_data, six.binary_type):
                req_data = req_data.decode('utf-8')
            if not isinstance(body, six.string_types):
                # json load if the input body to match against is not a string
                req_data = jsonutils.loads(req_data)
            self.assertEqual(req_data, body)
Exemplo n.º 10
0
 def post_os_floating_ips_bulk(request, context):
     body = jsonutils.loads(request.body)
     params = body.get('floating_ips_bulk_create')
     pool = params.get('pool', 'defaultPool')
     interface = params.get('interface', 'defaultInterface')
     return {
         'floating_ips_bulk_create': {
              'ip_range': '192.168.1.0/30',
              'pool': pool,
              'interface': interface
         }
     }
Exemplo n.º 11
0
 def post_os_floating_ips_bulk(request, context):
     body = jsonutils.loads(request.body)
     params = body.get('floating_ips_bulk_create')
     pool = params.get('pool', 'defaultPool')
     interface = params.get('interface', 'defaultInterface')
     return {
         'floating_ips_bulk_create': {
             'ip_range': '192.168.1.0/30',
             'pool': pool,
             'interface': interface
         }
     }
Exemplo n.º 12
0
        def put_os_floating_ip_dns_testdomain(request, context):
            body = jsonutils.loads(request.body)
            if body['domain_entry']['scope'] == 'private':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['availability_zone', 'scope'])
            elif body['domain_entry']['scope'] == 'public':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])
            else:
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])

            return request.body
Exemplo n.º 13
0
 def post_os_floating_ips_bulk(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     params = body.get('floating_ips_bulk_create')
     pool = params.get('pool', 'defaultPool')
     interface = params.get('interface', 'defaultInterface')
     data = {
         'floating_ips_bulk_create': {
              'ip_range': '192.168.1.0/30',
              'pool': pool,
              'interface': interface
         }
     }
     return 200, headers, jsonutils.dumps(data)
Exemplo n.º 14
0
 def post_os_floating_ips_bulk(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     params = body.get('floating_ips_bulk_create')
     pool = params.get('pool', 'defaultPool')
     interface = params.get('interface', 'defaultInterface')
     data = {
         'floating_ips_bulk_create': {
             'ip_range': '192.168.1.0/30',
             'pool': pool,
             'interface': interface
         }
     }
     return 200, headers, jsonutils.dumps(data)
Exemplo n.º 15
0
        def put_os_floating_ip_dns_testdomain(request, context):
            body = jsonutils.loads(request.body)
            if body['domain_entry']['scope'] == 'private':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['availability_zone', 'scope'])
            elif body['domain_entry']['scope'] == 'public':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])
            else:
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])

            return request.body
Exemplo n.º 16
0
    def post_servers(self, request, url, headers):
        body = jsonutils.loads(request.body.decode('utf-8'))
        assert set(body.keys()) <= set(['server'])
        fakes.assert_has_keys(body['server'],
                        required=['name', 'image_ref', 'flavor_ref'],
                        optional=['metadata', 'personality',
                                  'os-scheduler-hints:scheduler_hints'])
        if body['server']['name'] == 'some-bad-server':
            body = self.server_1235
        else:
            body = self.server_1234

        return 202, headers, jsonutils.dumps({'server': body})
Exemplo n.º 17
0
        def put_os_floating_ip_dns_testdomain(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            if body['domain_entry']['scope'] == 'private':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['availability_zone', 'scope'])
            elif body['domain_entry']['scope'] == 'public':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])
            else:
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])

            headers['Content-Type'] = 'application/json'
            return (205, headers, request.body)
Exemplo n.º 18
0
    def post_servers(self, request, context):
        body = jsonutils.loads(request.body)
        assert set(body.keys()) <= set(['server'])
        fakes.assert_has_keys(body['server'],
                        required=['name', 'image_ref', 'flavor_ref'],
                        optional=['metadata', 'personality',
                                  'os-scheduler-hints:scheduler_hints'])
        if body['server']['name'] == 'some-bad-server':
            body = self.server_1235
        else:
            body = self.server_1234

        context.status_code = 202
        return {'server': body}
Exemplo n.º 19
0
        def put_os_floating_ip_dns_testdomain(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            if body['domain_entry']['scope'] == 'private':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['availability_zone', 'scope'])
            elif body['domain_entry']['scope'] == 'public':
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])
            else:
                fakes.assert_has_keys(body['domain_entry'],
                                      required=['project', 'scope'])

            headers['Content-Type'] = 'application/json'
            return (205, headers, request.body)
Exemplo n.º 20
0
    def _rebuild_resize_disk_config(self, disk_config, operation="rebuild"):
        s = self.cs.servers.get(1234)

        if operation == "rebuild":
            s.rebuild(image=1, disk_config=disk_config)
        elif operation == "resize":
            s.resize(flavor=1, disk_config=disk_config)
        self.assert_called('POST', '/servers/1234/action')

        # verify disk config param was used in the request:
        body = jsonutils.loads(self.requests.last_request.body)

        d = body[operation]
        self.assertTrue('OS-DCF:diskConfig' in d)
        self.assertEqual(disk_config, d['OS-DCF:diskConfig'])
Exemplo n.º 21
0
    def post_servers(self, request, context):
        body = jsonutils.loads(request.body)
        assert set(body.keys()) <= set(["server"])
        fakes.assert_has_keys(
            body["server"],
            required=["name", "image_ref", "flavor_ref"],
            optional=["metadata", "personality", "os-scheduler-hints:scheduler_hints"],
        )
        if body["server"]["name"] == "some-bad-server":
            body = self.server_1235
        else:
            body = self.server_1234

        context.status_code = 202
        return {"server": body}
Exemplo n.º 22
0
    def _create_disk_config(self, disk_config):
        s = self.cs.servers.create(
            name="My server",
            image=1,
            flavor=1,
            disk_config=disk_config
        )
        self.assert_called('POST', '/servers')
        self.assertIsInstance(s, servers.Server)

        # verify disk config param was used in the request:
        body = jsonutils.loads(self.requests.last_request.body)
        server = body['server']
        self.assertTrue('OS-DCF:diskConfig' in server)
        self.assertEqual(disk_config, server['OS-DCF:diskConfig'])
Exemplo n.º 23
0
    def post_servers(self, request, url, headers):
        body = jsonutils.loads(request.body.decode('utf-8'))
        assert set(body.keys()) <= set(['server'])
        fakes.assert_has_keys(body['server'],
                              required=['name', 'image_ref', 'flavor_ref'],
                              optional=[
                                  'metadata', 'personality',
                                  'os-scheduler-hints:scheduler_hints'
                              ])
        if body['server']['name'] == 'some-bad-server':
            body = self.server_1235
        else:
            body = self.server_1234

        return 202, headers, jsonutils.dumps({'server': body})
Exemplo n.º 24
0
    def post_servers(self, request, context):
        body = jsonutils.loads(request.body)
        context.status_code = 202
        assert set(body.keys()) <= set(["server", "os:scheduler_hints"])
        fakes.assert_has_keys(
            body["server"], required=["name", "imageRef", "flavorRef"], optional=["metadata", "personality"]
        )
        if "personality" in body["server"]:
            for pfile in body["server"]["personality"]:
                fakes.assert_has_keys(pfile, required=["path", "contents"])
        if body["server"]["name"] == "some-bad-server":
            body = self.server_1235
        else:
            body = self.server_1234

        return {"server": body}
Exemplo n.º 25
0
    def post_servers(self, request, context):
        body = jsonutils.loads(request.body)
        context.status_code = 202
        assert (set(body.keys()) <=
                set(['server', 'os:scheduler_hints']))
        fakes.assert_has_keys(body['server'],
                              required=['name', 'imageRef', 'flavorRef'],
                              optional=['metadata', 'personality'])
        if 'personality' in body['server']:
            for pfile in body['server']['personality']:
                fakes.assert_has_keys(pfile, required=['path', 'contents'])
        if body['server']['name'] == 'some-bad-server':
            body = self.server_1235
        else:
            body = self.server_1234

        return {'server': body}
Exemplo n.º 26
0
        def post_os_volumes_boot(request, context):
            body = jsonutils.loads(request.body)
            assert set(body.keys()) <= set(["server", "os:scheduler_hints"])

            fakes.assert_has_keys(body["server"], required=["name", "flavorRef"], optional=["imageRef"])

            data = body["server"]

            # Require one, and only one, of the keys for bdm
            if "block_device_mapping" not in data:
                if "block_device_mapping_v2" not in data:
                    msg = "missing required keys: 'block_device_mapping'"
                    raise AssertionError(msg)
            elif "block_device_mapping_v2" in data:
                msg = "found extra keys: 'block_device_mapping'"
                raise AssertionError(msg)

            return {"server": self.server_9012}
Exemplo n.º 27
0
        def post_os_volumes_boot(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            assert (set(body.keys()) <= set(['server', 'os:scheduler_hints']))

            fakes.assert_has_keys(body['server'],
                                  required=['name', 'flavorRef'],
                                  optional=['imageRef'])

            data = body['server']

            # Require one, and only one, of the keys for bdm
            if 'block_device_mapping' not in data:
                if 'block_device_mapping_v2' not in data:
                    msg = "missing required keys: 'block_device_mapping'"
                    raise AssertionError(msg)
            elif 'block_device_mapping_v2' in data:
                msg = "found extra keys: 'block_device_mapping'"
                raise AssertionError(msg)

            return 202, headers, jsonutils.dumps({'server': self.server_9012})
Exemplo n.º 28
0
        def post_os_volumes_boot(request, context):
            body = jsonutils.loads(request.body)
            assert (set(body.keys()) <=
                    set(['server', 'os:scheduler_hints']))

            fakes.assert_has_keys(body['server'],
                                  required=['name', 'flavorRef'],
                                  optional=['imageRef'])

            data = body['server']

            # Require one, and only one, of the keys for bdm
            if 'block_device_mapping' not in data:
                if 'block_device_mapping_v2' not in data:
                    msg = "missing required keys: 'block_device_mapping'"
                    raise AssertionError(msg)
            elif 'block_device_mapping_v2' in data:
                msg = "found extra keys: 'block_device_mapping'"
                raise AssertionError(msg)

            return {'server': self.server_9012}
Exemplo n.º 29
0
 def post_os_floating_ips(request, context):
     body = jsonutils.loads(request.body)
     ip = floating_ips[0].copy()
     ip['pool'] = body.get('pool')
     return {'floating_ip': ip}
Exemplo n.º 30
0
 def put_os_hosts_sample_host(request, context):
     result = {'host': 'dummy'}
     result.update(jsonutils.loads(request.body))
     return result
Exemplo n.º 31
0
 def put_os_hosts_sample_host(request, url, headers):
     result = {"host": "dummy"}
     result.update(jsonutils.loads(request.body.decode("utf-8")))
     return 200, headers, jsonutils.dumps(result)
Exemplo n.º 32
0
 def put_servers_1234(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     assert list(body) == ['server']
     fakes.assert_has_keys(body['server'],
                           optional=['name', 'adminPass'])
     return 204, headers, request.body
Exemplo n.º 33
0
 def put_dns_testdomain_entries_testname(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     fakes.assert_has_keys(body['dns_entry'],
                           required=['ip', 'dns_type'])
     return 205, headers, request.body
Exemplo n.º 34
0
 def put_os_hosts_sample_host(request, url, headers):
     result = {'host': 'dummy'}
     result.update(jsonutils.loads(request.body.decode('utf-8')))
     return 200, headers, jsonutils.dumps(result)
Exemplo n.º 35
0
 def put_dns_testdomain_entries_testname(request, context):
     body = jsonutils.loads(request.body)
     fakes.assert_has_keys(body['dns_entry'],
                           required=['ip', 'dns_type'])
     context.status_code = 205
     return request.body
Exemplo n.º 36
0
 def post_os_floating_ips(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     ip = floating_ips[0].copy()
     ip['pool'] = body.get('pool')
     ip = jsonutils.dumps({'floating_ip': ip})
     return 200, headers, ip
Exemplo n.º 37
0
 def put_servers_1234(request, context):
     body = jsonutils.loads(request.body)
     assert list(body) == ['server']
     fakes.assert_has_keys(body['server'],
                           optional=['name', 'adminPass'])
     return request.body
Exemplo n.º 38
0
 def post_os_keypairs(request, context):
     body = jsonutils.loads(request.body)
     assert list(body) == ['keypair']
     fakes.assert_has_keys(body['keypair'], required=['name'])
     return {'keypair': keypair}
Exemplo n.º 39
0
 def post_os_networks(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     data = jsonutils.dumps({'network': body})
     return 202, headers, data
Exemplo n.º 40
0
 def put_dns_testdomain_entries_testname(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     fakes.assert_has_keys(body['dns_entry'],
                           required=['ip', 'dns_type'])
     return 205, headers, request.body
Exemplo n.º 41
0
 def post_os_networks(request, context):
     body = jsonutils.loads(request.body)
     return {'network': body}
Exemplo n.º 42
0
 def post_os_keypairs(request, context):
     body = jsonutils.loads(request.body)
     assert list(body) == ['keypair']
     fakes.assert_has_keys(body['keypair'], required=['name'])
     return {'keypair': keypair}
Exemplo n.º 43
0
 def put_os_floating_ips_bulk_delete(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     ip_range = body.get('ip_range')
     data = {'floating_ips_bulk_delete': ip_range}
     return 200, headers, jsonutils.dumps(data)
Exemplo n.º 44
0
 def put_os_floating_ips_bulk_delete(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     ip_range = body.get('ip_range')
     data = {'floating_ips_bulk_delete': ip_range}
     return 200, headers, jsonutils.dumps(data)
Exemplo n.º 45
0
 def put_os_floating_ips_bulk_delete(request, context):
     body = jsonutils.loads(request.body)
     ip_range = body.get('ip_range')
     return {'floating_ips_bulk_delete': ip_range}
Exemplo n.º 46
0
 def post_servers_1234_action(self, request, context):
     _body = ''
     body = jsonutils.loads(request.body)
     context.status_code = 202
     assert len(body.keys()) == 1
     action = list(body)[0]
     if action == 'reboot':
         assert list(body[action]) == ['type']
         assert body[action]['type'] in ['HARD', 'SOFT']
     elif action == 'rebuild':
         body = body[action]
         adminPass = body.get('adminPass', 'randompassword')
         assert 'imageRef' in body
         _body = self.server_1234.copy()
         _body['adminPass'] = adminPass
     elif action == 'resize':
         keys = body[action].keys()
         assert 'flavorRef' in keys
     elif action == 'confirmResize':
         assert body[action] is None
         # This one method returns a different response code
         context.status_code = 204
         return None
     elif action == 'revertResize':
         assert body[action] is None
     elif action == 'migrate':
         assert body[action] is None
     elif action == 'os-stop':
         assert body[action] is None
     elif action == 'os-start':
         assert body[action] is None
     elif action == 'forceDelete':
         assert body[action] is None
     elif action == 'restore':
         assert body[action] is None
     elif action == 'pause':
         assert body[action] is None
     elif action == 'unpause':
         assert body[action] is None
     elif action == 'lock':
         assert body[action] is None
     elif action == 'unlock':
         assert body[action] is None
     elif action == 'rescue':
         assert body[action] is None
         _body = {'Password': '******'}
     elif action == 'unrescue':
         assert body[action] is None
     elif action == 'resume':
         assert body[action] is None
     elif action == 'suspend':
         assert body[action] is None
     elif action == 'lock':
         assert body[action] is None
     elif action == 'unlock':
         assert body[action] is None
     elif action == 'shelve':
         assert body[action] is None
     elif action == 'shelveOffload':
         assert body[action] is None
     elif action == 'unshelve':
         assert body[action] is None
     elif action == 'addFixedIp':
         assert list(body[action]) == ['networkId']
     elif action == 'removeFixedIp':
         assert list(body[action]) == ['address']
     elif action == 'addFloatingIp':
         assert (list(body[action]) == ['address'] or
                 sorted(list(body[action])) == ['address',
                                                'fixed_address'])
     elif action == 'removeFloatingIp':
         assert list(body[action]) == ['address']
     elif action == 'createImage':
         assert set(body[action].keys()) == set(['name', 'metadata'])
         context.headers['location'] = "http://blah/images/456"
     elif action == 'changePassword':
         assert list(body[action]) == ['adminPass']
     elif action == 'os-getConsoleOutput':
         assert list(body[action]) == ['length']
         context.status_code = 202
         return {'output': 'foo'}
     elif action == 'os-getVNCConsole':
         assert list(body[action]) == ['type']
     elif action == 'os-getSPICEConsole':
         assert list(body[action]) == ['type']
     elif action == 'os-getRDPConsole':
         assert list(body[action]) == ['type']
     elif action == 'os-migrateLive':
         assert set(body[action].keys()) == set(['host',
                                                 'block_migration',
                                                 'disk_over_commit'])
     elif action == 'os-resetState':
         assert list(body[action]) == ['state']
     elif action == 'resetNetwork':
         assert body[action] is None
     elif action == 'addSecurityGroup':
         assert list(body[action]) == ['name']
     elif action == 'removeSecurityGroup':
         assert list(body[action]) == ['name']
     elif action == 'createBackup':
         assert set(body[action]) == set(['name',
                                          'backup_type',
                                          'rotation'])
     elif action == 'evacuate':
         keys = list(body[action])
         if 'adminPass' in keys:
             keys.remove('adminPass')
         assert set(keys) == set(['host', 'onSharedStorage'])
     else:
         raise AssertionError("Unexpected server action: %s" % action)
     return {'server': _body}
Exemplo n.º 47
0
    def post_servers_1234_action(self, request, context):
        context.status_code = 202
        body_is_none_list = [
            "revert_resize",
            "migrate",
            "stop",
            "start",
            "force_delete",
            "restore",
            "pause",
            "unpause",
            "lock",
            "unlock",
            "unrescue",
            "resume",
            "suspend",
            "lock",
            "unlock",
            "shelve",
            "shelve_offload",
            "unshelve",
            "reset_network",
            "rescue",
            "confirm_resize",
        ]
        body_return_map = {
            "rescue": {"admin_password": "******"},
            "get_console_output": {"output": "foo"},
            "rebuild": {"server": self.server_1234},
        }
        body_param_check_exists = {"rebuild": "image_ref", "resize": "flavor_ref"}
        body_params_check_exact = {
            "reboot": ["type"],
            "add_fixed_ip": ["network_id"],
            "evacuate": ["host", "on_shared_storage"],
            "remove_fixed_ip": ["address"],
            "change_password": ["admin_password"],
            "get_console_output": ["length"],
            "get_vnc_console": ["type"],
            "get_spice_console": ["type"],
            "get_serial_console": ["type"],
            "reset_state": ["state"],
            "create_image": ["name", "metadata"],
            "migrate_live": ["host", "block_migration", "disk_over_commit"],
            "create_backup": ["name", "backup_type", "rotation"],
            "attach": ["volume_id", "device"],
            "detach": ["volume_id"],
            "swap_volume_attachment": ["old_volume_id", "new_volume_id"],
        }

        body = jsonutils.loads(request.body)
        assert len(body.keys()) == 1
        action = list(body)[0]
        _body = body_return_map.get(action, "")

        if action in body_is_none_list:
            assert body[action] is None

        if action in body_param_check_exists:
            assert body_param_check_exists[action] in body[action]

        if action == "evacuate":
            body[action].pop("admin_password", None)

        if action in body_params_check_exact:
            assert set(body[action]) == set(body_params_check_exact[action])

        if action == "reboot":
            assert body[action]["type"] in ["HARD", "SOFT"]
        elif action == "confirm_resize":
            # This one method returns a different response code
            context.status_code = 204
        elif action == "create_image":
            context.headers["location"] = "http://blah/images/456"

        if action not in set.union(
            set(body_is_none_list), set(body_params_check_exact.keys()), set(body_param_check_exists.keys())
        ):
            raise AssertionError("Unexpected server action: %s" % action)

        return _body
Exemplo n.º 48
0
    def post_servers_1234_action(self, request, context):
        context.status_code = 202
        body_is_none_list = [
            'revert_resize', 'migrate', 'stop', 'start', 'force_delete',
            'restore', 'pause', 'unpause', 'lock', 'unlock', 'unrescue',
            'resume', 'suspend', 'lock', 'unlock', 'shelve', 'shelve_offload',
            'unshelve', 'reset_network', 'rescue', 'confirm_resize']
        body_return_map = {
            'rescue': {'admin_password': '******'},
            'get_console_output': {'output': 'foo'},
            'rebuild': {'server': self.server_1234},
            }
        body_param_check_exists = {
            'rebuild': 'image_ref',
            'resize': 'flavor_ref'}
        body_params_check_exact = {
            'reboot': ['type'],
            'add_fixed_ip': ['network_id'],
            'evacuate': ['host', 'on_shared_storage'],
            'remove_fixed_ip': ['address'],
            'change_password': ['admin_password'],
            'get_console_output': ['length'],
            'get_vnc_console': ['type'],
            'get_spice_console': ['type'],
            'reset_state': ['state'],
            'create_image': ['name', 'metadata'],
            'migrate_live': ['host', 'block_migration', 'disk_over_commit'],
            'create_backup': ['name', 'backup_type', 'rotation'],
            'attach': ['volume_id', 'device'],
            'detach': ['volume_id'],
            'swap_volume_attachment': ['old_volume_id', 'new_volume_id']}

        body = jsonutils.loads(request.body)
        assert len(body.keys()) == 1
        action = list(body)[0]
        _body = body_return_map.get(action, '')

        if action in body_is_none_list:
            assert body[action] is None

        if action in body_param_check_exists:
            assert body_param_check_exists[action] in body[action]

        if action == 'evacuate':
            body[action].pop('admin_password', None)

        if action in body_params_check_exact:
            assert set(body[action]) == set(body_params_check_exact[action])

        if action == 'reboot':
            assert body[action]['type'] in ['HARD', 'SOFT']
        elif action == 'confirm_resize':
            # This one method returns a different response code
            context.status_code = 204
        elif action == 'create_image':
            context.headers['location'] = "http://blah/images/456"

        if action not in set.union(set(body_is_none_list),
                                     set(body_params_check_exact.keys()),
                                     set(body_param_check_exists.keys())):
            raise AssertionError("Unexpected server action: %s" % action)

        return _body
Exemplo n.º 49
0
 def post_os_floating_ips(request, url, headers):
     body = jsonutils.loads(request.body.decode('utf-8'))
     ip = floating_ips[0].copy()
     ip['pool'] = body.get('pool')
     ip = jsonutils.dumps({'floating_ip': ip})
     return 200, headers, ip