Exemplo n.º 1
0
    def setUp(self):
        super(V3, self).setUp()

        get_os_hypervisors_search = {
            'hypervisors': [
                {'id': 1234, 'hypervisor_hostname': 'hyper1'},
                {'id': 5678, 'hypervisor_hostname': 'hyper2'}
            ]
        }

        httpretty.register_uri(httpretty.GET,
                               self.url('search', query='hyper'),
                               body=jsonutils.dumps(get_os_hypervisors_search),
                               content_type='application/json')

        get_1234_servers = {
            'hypervisor': {
                'id': 1234,
                'hypervisor_hostname': 'hyper1',
                'servers': [
                    {'name': 'inst1', 'id': 'uuid1'},
                    {'name': 'inst2', 'id': 'uuid2'}
                ]
            },
        }

        httpretty.register_uri(httpretty.GET, self.url(1234, 'servers'),
                               body=jsonutils.dumps(get_1234_servers),
                               content_type='application/json')
Exemplo n.º 2
0
    def setUp(self):
        super(Fixture, self).setUp()

        post_os_agents = {
            'agent': {
                'url': '/xxx/xxx/xxx',
                'hypervisor': 'kvm',
                'md5hash': 'add6bb58e139be103324d04d82d8f546',
                'version': '7.0',
                'architecture': 'x86',
                'os': 'win',
                'id': 1
            }
        }

        httpretty.register_uri(httpretty.POST, self.url(),
                               body=jsonutils.dumps(post_os_agents),
                               content_type='application/json')

        put_os_agents_1 = {
            "agent": {
                "url": "/yyy/yyyy/yyyy",
                "version": "8.0",
                "md5hash": "add6bb58e139be103324d04d82d8f546",
                'id': 1
            }
        }

        httpretty.register_uri(httpretty.PUT, self.url(1),
                               body=jsonutils.dumps(put_os_agents_1),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE, self.url(1),
                               content_type='application/json',
                               status=202)
Exemplo n.º 3
0
    def setUp(self):
        super(V1, self).setUp()
        keypair = {'fingerprint': 'FAKE_KEYPAIR', 'name': 'test'}

        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps({'keypairs': [keypair]}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.GET,
                               self.url('test'),
                               body=jsonutils.dumps({'keypair': keypair}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE, self.url('test'), status=202)

        def post_os_keypairs(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            assert list(body) == ['keypair']
            fakes.assert_has_keys(body['keypair'], required=['name'])
            return 202, headers, jsonutils.dumps({'keypair': keypair})

        httpretty.register_uri(httpretty.POST,
                               self.url(),
                               body=post_os_keypairs,
                               content_type='application/json')
Exemplo n.º 4
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_fping_1 = {
            'server': {
                "id": "1",
                "project_id": "fake-project",
                "alive": True,
            }
        }
        httpretty.register_uri(httpretty.GET,
                               self.url(1),
                               body=jsonutils.dumps(get_os_fping_1),
                               content_type='application/json')

        get_os_fping = {
            'servers': [
                get_os_fping_1['server'],
                {
                    "id": "2",
                    "project_id": "fake-project",
                    "alive": True,
                },
            ]
        }
        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_os_fping),
                               content_type='application/json')
Exemplo n.º 5
0
    def setUp(self):
        super(Fixture, self).setUp()

        post_os_agents = {
            "agent": {
                "url": "/xxx/xxx/xxx",
                "hypervisor": "kvm",
                "md5hash": "add6bb58e139be103324d04d82d8f546",
                "version": "7.0",
                "architecture": "x86",
                "os": "win",
                "id": 1,
            }
        }

        httpretty.register_uri(
            httpretty.POST, self.url(), body=jsonutils.dumps(post_os_agents), content_type="application/json"
        )

        put_os_agents_1 = {
            "agent": {"url": "/yyy/yyyy/yyyy", "version": "8.0", "md5hash": "add6bb58e139be103324d04d82d8f546", "id": 1}
        }

        httpretty.register_uri(
            httpretty.PUT, self.url(1), body=jsonutils.dumps(put_os_agents_1), content_type="application/json"
        )

        httpretty.register_uri(httpretty.DELETE, self.url(1), content_type="application/json", status=202)
Exemplo n.º 6
0
    def setUp(self):
        super(V1, self).setUp()

        uuid = '97f4c221-bff4-4578-b030-0df4ef119353'
        uuid2 = '97f4c221bff44578b0300df4ef119353'
        test_json = jsonutils.dumps({'quota_set': self.test_quota('test')})

        for u in ('test', 'tenant-id', 'tenant-id/defaults',
                  '%s/defaults' % uuid2):
            httpretty.register_uri(httpretty.GET, self.url(u),
                                   body=test_json,
                                   content_type='application/json')

        quota_json = jsonutils.dumps({'quota_set': self.test_quota(uuid)})
        httpretty.register_uri(httpretty.PUT, self.url(uuid),
                               body=quota_json,
                               content_type='application/json')
        httpretty.register_uri(httpretty.GET, self.url(uuid),
                               body=quota_json,
                               content_type='application/json')

        quota_json2 = jsonutils.dumps({'quota_set': self.test_quota(uuid2)})
        httpretty.register_uri(httpretty.PUT, self.url(uuid2),
                               body=quota_json2,
                               content_type='application/json')
        httpretty.register_uri(httpretty.GET, self.url(uuid2),
                               body=quota_json2,
                               content_type='application/json')

        for u in ('test', uuid2):
            httpretty.register_uri(httpretty.DELETE, self.url(u), status=202)
Exemplo n.º 7
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_aggregates = {"aggregates": [
            {'id': '1',
             'name': 'test',
             'availability_zone': 'nova1'},
            {'id': '2',
             'name': 'test2',
             'availability_zone': 'nova1'},
        ]}

        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_os_aggregates),
                               content_type='application/json')

        r = jsonutils.dumps({'aggregate': get_os_aggregates['aggregates'][0]})

        httpretty.register_uri(httpretty.POST, self.url(), body=r,
                               content_type='application/json')

        for agg_id in (1, 2):
            for method in (httpretty.GET, httpretty.PUT):
                httpretty.register_uri(method, self.url(agg_id), body=r,
                                       content_type='application/json')

            httpretty.register_uri(httpretty.POST, self.url(agg_id, 'action'),
                                   body=r, content_type='application/json')

        httpretty.register_uri(httpretty.DELETE, self.url(1), status=202)
Exemplo n.º 8
0
    def setUp(self):
        super(FloatingFixture, self).setUp()

        floating_ips = [{'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1'},
                        {'id': 2, 'fixed_ip': '10.0.0.2', 'ip': '11.0.0.2'}]

        get_os_floating_ips = {'floating_ips': floating_ips}
        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_os_floating_ips),
                               content_type='application/json')

        for ip in floating_ips:
            get_os_floating_ip = {'floating_ip': ip}
            httpretty.register_uri(httpretty.GET, self.url(ip['id']),
                                   body=jsonutils.dumps(get_os_floating_ip),
                                   content_type='application/json')

            httpretty.register_uri(httpretty.DELETE, self.url(ip['id']),
                                   content_type='application/json',
                                   status=204)

        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
        httpretty.register_uri(httpretty.POST, self.url(),
                               body=post_os_floating_ips,
                               content_type='application/json')
Exemplo n.º 9
0
    def setUp(self):
        super(V1, self).setUp()

        #
        # Server Addresses
        #

        add = self.server_1234['addresses']
        httpretty.register_uri(httpretty.GET, self.url(1234, 'ips'),
                               jsonutils.dumps({'addresses': add}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.GET, self.url(1234, 'ips', 'public'),
                               jsonutils.dumps({'public': add['public']}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.GET, self.url(1234, 'ips', 'private'),
                               jsonutils.dumps({'private': add['private']}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE,
                               self.url(1234, 'ips', 'public', '1.2.3.4'),
                               status=202)

        httpretty.register_uri(httpretty.GET,
                               self.url('1234', 'diagnostics'),
                               body=self.diagnostic,
                               status=200)

        httpretty.register_uri(httpretty.DELETE,
                               self.url('1234', 'os-interface', 'port-id'))

        # Testing with the following password and key
        #
        # Clear password: FooBar123
        #
        # RSA Private Key: novaclient/tests/idfake.pem
        #
        # Encrypted password
        # OIuEuQttO8Rk93BcKlwHQsziDAnkAm/V6V8VPToA8ZeUaUBWwS0gwo2K6Y61Z96r
        # qG447iRz0uTEEYq3RAYJk1mh3mMIRVl27t8MtIecR5ggVVbz1S9AwXJQypDKl0ho
        # QFvhCBcMWPohyGewDJOhDbtuN1IoFI9G55ZvFwCm5y7m7B2aVcoLeIsJZE4PLsIw
        # /y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N
        # tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk
        # Hi/fmZZNQQqj1Ijq0caOIw==

        get_server_password = {'password':
            '******'
            'qG447iRz0uTEEYq3RAYJk1mh3mMIRVl27t8MtIecR5ggVVbz1S9AwXJQypDKl0ho'
            'QFvhCBcMWPohyGewDJOhDbtuN1IoFI9G55ZvFwCm5y7m7B2aVcoLeIsJZE4PLsIw'
            '/y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N'
            'tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk'
            'Hi/fmZZNQQqj1Ijq0caOIw=='}
        httpretty.register_uri(httpretty.GET,
                               self.url(1234, 'os-server-password'),
                               jsonutils.dumps(get_server_password))
Exemplo n.º 10
0
    def setUp(self):
        super(BulkFixture, self).setUp()

        get_os_floating_ips_bulk = {
            'floating_ip_info': [
                {
                    'id': 1,
                    'fixed_ip': '10.0.0.1',
                    'ip': '11.0.0.1'
                },
                {
                    'id': 2,
                    'fixed_ip': '10.0.0.2',
                    'ip': '11.0.0.2'
                },
            ]
        }
        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_os_floating_ips_bulk),
                               content_type='application/json')
        httpretty.register_uri(httpretty.GET,
                               self.url('testHost'),
                               body=jsonutils.dumps(get_os_floating_ips_bulk),
                               content_type='application/json')

        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)

        httpretty.register_uri(httpretty.PUT,
                               self.url('delete'),
                               body=put_os_floating_ips_bulk_delete,
                               content_type='application/json')

        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)

        httpretty.register_uri(httpretty.POST,
                               self.url(),
                               body=post_os_floating_ips_bulk,
                               content_type='application/json')
Exemplo n.º 11
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_fping_1 = {"server": {"id": "1", "project_id": "fake-project", "alive": True}}
        httpretty.register_uri(
            httpretty.GET, self.url(1), body=jsonutils.dumps(get_os_fping_1), content_type="application/json"
        )

        get_os_fping = {"servers": [get_os_fping_1["server"], {"id": "2", "project_id": "fake-project", "alive": True}]}
        httpretty.register_uri(
            httpretty.GET, self.url(), body=jsonutils.dumps(get_os_fping), content_type="application/json"
        )
Exemplo n.º 12
0
    def setUp(self):
        super(Fixture, self).setUp()

        server_groups = [
            {
                "members": [],
                "metadata": {},
                "id": "2cbd51f4-fafe-4cdb-801b-cf913a6f288b",
                "policies": [],
                "name": "ig1"
            },
            {
                "members": [],
                "metadata": {},
                "id": "4473bb03-4370-4bfb-80d3-dc8cffc47d94",
                "policies": ["anti-affinity"],
                "name": "ig2"
            },
            {
                "members": [],
                "metadata": {"key": "value"},
                "id": "31ab9bdb-55e1-4ac3-b094-97eeb1b65cc4",
                "policies": [], "name": "ig3"
            },
            {
                "members": ["2dccb4a1-02b9-482a-aa23-5799490d6f5d"],
                "metadata": {},
                "id": "4890bb03-7070-45fb-8453-d34556c87d94",
                "policies": ["anti-affinity"],
                "name": "ig2"
            }
        ]

        get_server_groups = {'server_groups': server_groups}
        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_server_groups),
                               content_type='application/json')

        server = server_groups[0]
        server_json = jsonutils.dumps({'server_group': server})

        def _register(method, *args):
            httpretty.register_uri(method, self.url(*args), body=server_json)

        _register(httpretty.POST)
        _register(httpretty.POST, server['id'])
        _register(httpretty.GET, server['id'])
        _register(httpretty.PUT, server['id'])
        _register(httpretty.POST, server['id'], '/action')

        httpretty.register_uri(httpretty.DELETE, self.url(server['id']),
                               status=202)
Exemplo n.º 13
0
    def setUp(self):
        super(Fixture, self).setUp()

        server_groups = [{
            "members": [],
            "metadata": {},
            "id": "2cbd51f4-fafe-4cdb-801b-cf913a6f288b",
            "policies": [],
            "name": "ig1"
        }, {
            "members": [],
            "metadata": {},
            "id": "4473bb03-4370-4bfb-80d3-dc8cffc47d94",
            "policies": ["anti-affinity"],
            "name": "ig2"
        }, {
            "members": [],
            "metadata": {
                "key": "value"
            },
            "id": "31ab9bdb-55e1-4ac3-b094-97eeb1b65cc4",
            "policies": [],
            "name": "ig3"
        }, {
            "members": ["2dccb4a1-02b9-482a-aa23-5799490d6f5d"],
            "metadata": {},
            "id": "4890bb03-7070-45fb-8453-d34556c87d94",
            "policies": ["anti-affinity"],
            "name": "ig2"
        }]

        get_server_groups = {'server_groups': server_groups}
        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_server_groups),
                               content_type='application/json')

        server = server_groups[0]
        server_json = jsonutils.dumps({'server_group': server})

        def _register(method, *args):
            httpretty.register_uri(method, self.url(*args), body=server_json)

        _register(httpretty.POST)
        _register(httpretty.POST, server['id'])
        _register(httpretty.GET, server['id'])
        _register(httpretty.PUT, server['id'])
        _register(httpretty.POST, server['id'], '/action')

        httpretty.register_uri(httpretty.DELETE,
                               self.url(server['id']),
                               status=202)
Exemplo n.º 14
0
    def setUp(self):
        super(V3, self).setUp()

        get_detail = {
            'quota_set': {
                'cores': {
                    'reserved': 0,
                    'in_use': 0,
                    'limit': 10
                },
                'instances': {
                    'reserved': 0,
                    'in_use': 4,
                    'limit': 50
                },
                'ram': {
                    'reserved': 0,
                    'in_use': 1024,
                    'limit': 51200
                }
            }
        }

        httpretty.register_uri(httpretty.GET,
                               self.url('test', 'detail'),
                               body=jsonutils.dumps(get_detail),
                               content_type='application/json')
Exemplo n.º 15
0
    def stub_hypervisors(self, hypervisor='kvm'):
        get_os_agents = {'agents':
            [
                {
                    'hypervisor': hypervisor,
                    'os': 'win',
                    'architecture': 'x86',
                    'version': '7.0',
                    'url': 'xxx://xxxx/xxx/xxx',
                    'md5hash': 'add6bb58e139be103324d04d82d8f545',
                    'id': 1
                },
                {
                    'hypervisor': hypervisor,
                    'os': 'linux',
                    'architecture': 'x86',
                    'version': '16.0',
                    'url': 'xxx://xxxx/xxx/xxx1',
                    'md5hash': 'add6bb58e139be103324d04d82d8f546',
                    'id': 2
                },
            ]
        }

        httpretty.register_uri(httpretty.GET, self.data_fixture.url(),
                               body=jsonutils.dumps(get_os_agents),
                               content_type='application/json')
Exemplo n.º 16
0
def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
    pt = prettytable.PrettyTable([dict_property, dict_value], caching=False)
    pt.align = 'l'
    for k, v in sorted(d.items()):
        # convert dict to str to check length
        if isinstance(v, (dict, list)):
            v = jsonutils.dumps(v)
        if wrap > 0:
            v = textwrap.fill(str(v), wrap)
        # if value has a newline, add in multiple rows
        # e.g. fault with stacktrace
        if v and isinstance(v, six.string_types) and r'\n' in v:
            lines = v.strip().split(r'\n')
            col1 = k
            for line in lines:
                pt.add_row([col1, line])
                col1 = ''
        else:
            if v is None:
                v = '-'
            pt.add_row([k, v])

    result = encodeutils.safe_encode(pt.get_string())

    if six.PY3:
        result = result.decode()

    print(result)
Exemplo n.º 17
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.º 18
0
def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
    pt = prettytable.PrettyTable([dict_property, dict_value], caching=False)
    pt.align = 'l'
    for k, v in sorted(d.items()):
        # convert dict to str to check length
        if isinstance(v, (dict, list)):
            v = jsonutils.dumps(v)
        if wrap > 0:
            v = textwrap.fill(str(v), wrap)
        # if value has a newline, add in multiple rows
        # e.g. fault with stacktrace
        if v and isinstance(v, six.string_types) and r'\n' in v:
            lines = v.strip().split(r'\n')
            col1 = k
            for line in lines:
                pt.add_row([col1, line])
                col1 = ''
        else:
            if v is None:
                v = '-'
            pt.add_row([k, v])

    result = strutils.safe_encode(pt.get_string())

    print(result)
Exemplo n.º 19
0
    def setUp(self):
        super(Fixture, self).setUp()

        rule = {
            'id': 1,
            'parent_group_id': 1,
            'group_id': 2,
            'ip_protocol': 'TCP',
            'from_port': '22',
            'to_port': 22,
            'cidr': '10.0.0.0/8'
        }

        get_rules = {'security_group_rules': [rule]}
        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_rules),
                               content_type='application/json')

        for u in (1, 11, 12):
            httpretty.register_uri(httpretty.DELETE, self.url(u), status=202)

        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})

        httpretty.register_uri(httpretty.POST, self.url(),
                               body=post_rules,
                               content_type='application/json')
Exemplo n.º 20
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_limits = {
            "limits": {
                "rate": [
                    {
                        "uri": "*",
                        "regex": ".*",
                        "limit": [
                            {
                                "value": 10,
                                "verb": "POST",
                                "remaining": 2,
                                "unit": "MINUTE",
                                "next-available": "2011-12-15T22:42:45Z"
                            },
                            {
                                "value": 10,
                                "verb": "PUT",
                                "remaining": 2,
                                "unit": "MINUTE",
                                "next-available": "2011-12-15T22:42:45Z"
                            },
                            {
                                "value": 100,
                                "verb": "DELETE",
                                "remaining": 100,
                                "unit": "MINUTE",
                                "next-available": "2011-12-15T22:42:45Z"
                            }
                        ]
                    },
                    {
                        "uri": "*/servers",
                        "regex": "^/servers",
                        "limit": [
                            {
                                "verb": "POST",
                                "value": 25,
                                "remaining": 24,
                                "unit": "DAY",
                                "next-available": "2011-12-15T22:42:45Z"
                            }
                        ]
                    }
                ],
                "absolute": {
                    "maxTotalRAMSize": 51200,
                    "maxServerMeta": 5,
                    "maxImageMeta": 5,
                    "maxPersonality": 5,
                    "maxPersonalitySize": 10240
                },
            },
        }

        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_limits),
                               content_type='application/json')
Exemplo n.º 21
0
    def stub_hypervisors(self, hypervisor='kvm'):
        get_os_agents = {'agents':
            [
                {
                    'hypervisor': hypervisor,
                    'os': 'win',
                    'architecture': 'x86',
                    'version': '7.0',
                    'url': 'xxx://xxxx/xxx/xxx',
                    'md5hash': 'add6bb58e139be103324d04d82d8f545',
                    'id': 1
                },
                {
                    'hypervisor': hypervisor,
                    'os': 'linux',
                    'architecture': 'x86',
                    'version': '16.0',
                    'url': 'xxx://xxxx/xxx/xxx1',
                    'md5hash': 'add6bb58e139be103324d04d82d8f546',
                    'id': 2
                },
            ]
        }

        httpretty.register_uri(httpretty.GET, self.data_fixture.url(),
                               body=jsonutils.dumps(get_os_agents),
                               content_type='application/json')
Exemplo n.º 22
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.º 23
0
    def setUp(self):
        super(V3, self).setUp()

        get_interfaces = {
            "interface_attachments": [{
                "port_state": "ACTIVE",
                "net_id": "net-id-1",
                "port_id": "port-id-1",
                "mac_address": "aa:bb:cc:dd:ee:ff",
                "fixed_ips": [{
                    "ip_address": "1.2.3.4"
                }],
            }, {
                "port_state": "ACTIVE",
                "net_id": "net-id-1",
                "port_id": "port-id-1",
                "mac_address": "aa:bb:cc:dd:ee:ff",
                "fixed_ips": [{
                    "ip_address": "1.2.3.4"
                }],
            }]
        }

        httpretty.register_uri(httpretty.GET,
                               self.url('1234', 'os-attach-interfaces'),
                               body=jsonutils.dumps(get_interfaces),
                               content_type='application/json')

        attach_body = {'interface_attachment': {}}
        httpretty.register_uri(httpretty.POST,
                               self.url('1234', 'os-attach-interfaces'),
                               body=jsonutils.dumps(attach_body),
                               content_type='application/json')

        httpretty.register_uri(httpretty.GET,
                               self.url('1234', 'os-server-diagnostics'),
                               body=self.diagnostic,
                               status=200)

        httpretty.register_uri(
            httpretty.DELETE,
            self.url('1234', 'os-attach-interfaces', 'port-id'))

        httpretty.register_uri(httpretty.GET,
                               self.url(1234, 'os-server-password'),
                               jsonutils.dumps({'password': ''}))
Exemplo n.º 24
0
    def setUp(self):
        super(V3, self).setUp()

        get_interfaces = {
            "interface_attachments": [
                {
                    "port_state": "ACTIVE",
                    "net_id": "net-id-1",
                    "port_id": "port-id-1",
                    "mac_address": "aa:bb:cc:dd:ee:ff",
                    "fixed_ips": [{"ip_address": "1.2.3.4"}],
                },
                {
                    "port_state": "ACTIVE",
                    "net_id": "net-id-1",
                    "port_id": "port-id-1",
                    "mac_address": "aa:bb:cc:dd:ee:ff",
                    "fixed_ips": [{"ip_address": "1.2.3.4"}],
                }
            ]
        }

        httpretty.register_uri(httpretty.GET,
                               self.url('1234', 'os-attach-interfaces'),
                               body=jsonutils.dumps(get_interfaces),
                               content_type='application/json')

        attach_body = {'interface_attachment': {}}
        httpretty.register_uri(httpretty.POST,
                               self.url('1234', 'os-attach-interfaces'),
                               body=jsonutils.dumps(attach_body),
                               content_type='application/json')

        httpretty.register_uri(httpretty.GET,
                               self.url('1234', 'os-server-diagnostics'),
                               body=self.diagnostic,
                               status=200)

        httpretty.register_uri(httpretty.DELETE,
                               self.url('1234', 'os-attach-interfaces',
                                        'port-id'))

        httpretty.register_uri(httpretty.GET,
                               self.url(1234, 'os-server-password'),
                               jsonutils.dumps({'password': ''}))
Exemplo n.º 25
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})
Exemplo n.º 26
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_cloudpipe = {'cloudpipes': [{'project_id': 1}]}
        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_os_cloudpipe),
                               content_type='application/json')

        instance_id = '9d5824aa-20e6-4b9f-b967-76a699fc51fd'
        post_os_cloudpipe = {'instance_id': instance_id}
        httpretty.register_uri(httpretty.POST, self.url(),
                               body=jsonutils.dumps(post_os_cloudpipe),
                               content_type='application/json',
                               status=202)

        httpretty.register_uri(httpretty.PUT, self.url('configure-project'),
                               content_type='application/json',
                               status=202)
Exemplo n.º 27
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_limits = {
            "limits": {
                "rate": [{
                    "uri":
                    "*",
                    "regex":
                    ".*",
                    "limit": [{
                        "value": 10,
                        "verb": "POST",
                        "remaining": 2,
                        "unit": "MINUTE",
                        "next-available": "2011-12-15T22:42:45Z"
                    }, {
                        "value": 10,
                        "verb": "PUT",
                        "remaining": 2,
                        "unit": "MINUTE",
                        "next-available": "2011-12-15T22:42:45Z"
                    }, {
                        "value": 100,
                        "verb": "DELETE",
                        "remaining": 100,
                        "unit": "MINUTE",
                        "next-available": "2011-12-15T22:42:45Z"
                    }]
                }, {
                    "uri":
                    "*/servers",
                    "regex":
                    "^/servers",
                    "limit": [{
                        "verb": "POST",
                        "value": 25,
                        "remaining": 24,
                        "unit": "DAY",
                        "next-available": "2011-12-15T22:42:45Z"
                    }]
                }],
                "absolute": {
                    "maxTotalRAMSize": 51200,
                    "maxServerMeta": 5,
                    "maxImageMeta": 5,
                    "maxPersonality": 5,
                    "maxPersonalitySize": 10240
                },
            },
        }

        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_limits),
                               content_type='application/json')
Exemplo n.º 28
0
    def setUp(self):
        super(V1, self).setUp()
        httpretty.enable()
        self.addCleanup(httpretty.disable)

        auth_url = '%s/tokens' % self.identity_url
        httpretty.register_uri(httpretty.POST, auth_url,
                               body=jsonutils.dumps(self.token),
                               content_type='application/json')
        self.client = self.new_client()
Exemplo n.º 29
0
    def setUp(self):
        super(V1, self).setUp()
        httpretty.enable()
        self.addCleanup(httpretty.disable)

        auth_url = '%s/tokens' % self.identity_url
        httpretty.register_uri(httpretty.POST, auth_url,
                               body=jsonutils.dumps(self.token),
                               content_type='application/json')
        self.client = self.new_client()
Exemplo n.º 30
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_aggregates = {
            "aggregates": [
                {
                    'id': '1',
                    'name': 'test',
                    'availability_zone': 'nova1'
                },
                {
                    'id': '2',
                    'name': 'test2',
                    'availability_zone': 'nova1'
                },
            ]
        }

        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_os_aggregates),
                               content_type='application/json')

        r = jsonutils.dumps({'aggregate': get_os_aggregates['aggregates'][0]})

        httpretty.register_uri(httpretty.POST,
                               self.url(),
                               body=r,
                               content_type='application/json')

        for agg_id in (1, 2):
            for method in (httpretty.GET, httpretty.PUT):
                httpretty.register_uri(method,
                                       self.url(agg_id),
                                       body=r,
                                       content_type='application/json')

            httpretty.register_uri(httpretty.POST,
                                   self.url(agg_id, 'action'),
                                   body=r,
                                   content_type='application/json')

        httpretty.register_uri(httpretty.DELETE, self.url(1), status=202)
Exemplo n.º 31
0
    def setUp(self):
        super(BulkFixture, self).setUp()

        get_os_floating_ips_bulk = {
            'floating_ip_info': [
                {'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1'},
                {'id': 2, 'fixed_ip': '10.0.0.2', 'ip': '11.0.0.2'},
            ]
        }
        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_os_floating_ips_bulk),
                               content_type='application/json')
        httpretty.register_uri(httpretty.GET, self.url('testHost'),
                               body=jsonutils.dumps(get_os_floating_ips_bulk),
                               content_type='application/json')

        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)

        httpretty.register_uri(httpretty.PUT, self.url('delete'),
                               body=put_os_floating_ips_bulk_delete,
                               content_type='application/json')

        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)

        httpretty.register_uri(httpretty.POST, self.url(),
                               body=post_os_floating_ips_bulk,
                               content_type='application/json')
Exemplo n.º 32
0
    def setUp(self):
        super(FloatingFixture, self).setUp()

        floating_ips = [{
            'id': 1,
            'fixed_ip': '10.0.0.1',
            'ip': '11.0.0.1'
        }, {
            'id': 2,
            'fixed_ip': '10.0.0.2',
            'ip': '11.0.0.2'
        }]

        get_os_floating_ips = {'floating_ips': floating_ips}
        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_os_floating_ips),
                               content_type='application/json')

        for ip in floating_ips:
            get_os_floating_ip = {'floating_ip': ip}
            httpretty.register_uri(httpretty.GET,
                                   self.url(ip['id']),
                                   body=jsonutils.dumps(get_os_floating_ip),
                                   content_type='application/json')

            httpretty.register_uri(httpretty.DELETE,
                                   self.url(ip['id']),
                                   content_type='application/json',
                                   status=204)

        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

        httpretty.register_uri(httpretty.POST,
                               self.url(),
                               body=post_os_floating_ips,
                               content_type='application/json')
Exemplo n.º 33
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_networks = {
            'networks': [{
                "label": "1",
                "cidr": "10.0.0.0/24",
                'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
                'id': '1'
            }]
        }

        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_os_networks),
                               content_type='application/json')

        def post_os_networks(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            data = jsonutils.dumps({'network': body})
            return 202, headers, data

        httpretty.register_uri(httpretty.POST,
                               self.url(),
                               body=post_os_networks,
                               content_type='application/json')

        get_os_networks_1 = {'network': {"label": "1", "cidr": "10.0.0.0/24"}}

        httpretty.register_uri(httpretty.GET,
                               self.url(1),
                               body=jsonutils.dumps(get_os_networks_1),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE,
                               self.url('networkdelete'),
                               stauts=202)

        for u in ('add', 'networkdisassociate/action', 'networktest/action',
                  '1/action', '2/action'):
            httpretty.register_uri(httpretty.POST, self.url(u), stauts=202)
Exemplo n.º 34
0
    def setUp(self):
        super(PoolsFixture, self).setUp()

        get_os_floating_ip_pools = {
            'floating_ip_pools': [
                {'name': 'foo'},
                {'name': 'bar'}
            ]
        }
        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_os_floating_ip_pools),
                               content_type='application/json')
Exemplo n.º 35
0
    def setUp(self):
        super(Fixture, self).setUp()

        server_groups = [{
            "members": [],
            "metadata": {},
            "id": "2cbd51f4-fafe-4cdb-801b-cf913a6f288b",
            "policies": [],
            "name": "ig1"
        }, {
            "members": [],
            "metadata": {},
            "id": "4473bb03-4370-4bfb-80d3-dc8cffc47d94",
            "policies": ["anti-affinity"],
            "name": "ig2"
        }, {
            "members": [],
            "metadata": {
                "key": "value"
            },
            "id": "31ab9bdb-55e1-4ac3-b094-97eeb1b65cc4",
            "policies": [],
            "name": "ig3"
        }, {
            "members": ["2dccb4a1-02b9-482a-aa23-5799490d6f5d"],
            "metadata": {},
            "id": "4890bb03-7070-45fb-8453-d34556c87d94",
            "policies": ["anti-affinity"],
            "name": "ig2"
        }]

        headers = {'Content-Type': 'application/json'}

        self.requests.register_uri('GET',
                                   self.url(),
                                   json={'server_groups': server_groups},
                                   headers=headers)

        server = server_groups[0]
        server_j = jsonutils.dumps({'server_group': server})

        def _register(method, *args):
            self.requests.register_uri(method, self.url(*args), text=server_j)

        _register('POST')
        _register('POST', server['id'])
        _register('GET', server['id'])
        _register('PUT', server['id'])
        _register('POST', server['id'], '/action')

        self.requests.register_uri('DELETE',
                                   self.url(server['id']),
                                   status_code=202)
Exemplo n.º 36
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_networks = {
            'networks': [
                {
                    "label": "1",
                    "cidr": "10.0.0.0/24",
                    'project_id': '4ffc664c198e435e9853f2538fbcd7a7',
                    'id': '1'
                }
            ]
        }

        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps(get_os_networks),
                               content_type='application/json')

        def post_os_networks(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            data = jsonutils.dumps({'network': body})
            return 202, headers, data

        httpretty.register_uri(httpretty.POST, self.url(),
                               body=post_os_networks,
                               content_type='application/json')

        get_os_networks_1 = {'network': {"label": "1", "cidr": "10.0.0.0/24"}}

        httpretty.register_uri(httpretty.GET, self.url(1),
                               body=jsonutils.dumps(get_os_networks_1),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE,
                               self.url('networkdelete'),
                               stauts=202)

        for u in ('add', 'networkdisassociate/action', 'networktest/action',
                  '1/action', '2/action'):
            httpretty.register_uri(httpretty.POST, self.url(u), stauts=202)
Exemplo n.º 37
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.º 38
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.º 39
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.º 40
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_certificate = {
            'certificate': {
                'private_key': None,
                'data': 'foo'
            }
        }
        httpretty.register_uri(httpretty.GET, self.url('root'),
                               body=jsonutils.dumps(get_os_certificate),
                               content_type='application/json')

        post_os_certificates = {
            'certificate': {
                'private_key': 'foo',
                'data': 'bar'
             }
        }
        httpretty.register_uri(httpretty.POST, self.url(),
                               body=jsonutils.dumps(post_os_certificates),
                               content_type='application/json')
Exemplo n.º 41
0
    def setUp(self):
        super(Fixture, self).setUp()

        server_groups = [
            {
                "members": [],
                "metadata": {},
                "id": "2cbd51f4-fafe-4cdb-801b-cf913a6f288b",
                "policies": [],
                "name": "ig1",
            },
            {
                "members": [],
                "metadata": {},
                "id": "4473bb03-4370-4bfb-80d3-dc8cffc47d94",
                "policies": ["anti-affinity"],
                "name": "ig2",
            },
            {
                "members": [],
                "metadata": {"key": "value"},
                "id": "31ab9bdb-55e1-4ac3-b094-97eeb1b65cc4",
                "policies": [],
                "name": "ig3",
            },
            {
                "members": ["2dccb4a1-02b9-482a-aa23-5799490d6f5d"],
                "metadata": {},
                "id": "4890bb03-7070-45fb-8453-d34556c87d94",
                "policies": ["anti-affinity"],
                "name": "ig2",
            },
        ]

        headers = {"Content-Type": "application/json"}

        self.requests.register_uri("GET", self.url(), json={"server_groups": server_groups}, headers=headers)

        server = server_groups[0]
        server_j = jsonutils.dumps({"server_group": server})

        def _register(method, *args):
            self.requests.register_uri(method, self.url(*args), text=server_j)

        _register("POST")
        _register("POST", server["id"])
        _register("GET", server["id"])
        _register("PUT", server["id"])
        _register("POST", server["id"], "/action")

        self.requests.register_uri("DELETE", self.url(server["id"]), status_code=202)
Exemplo n.º 42
0
    def setUp(self):
        super(V1, self).setUp()
        keypair = {'fingerprint': 'FAKE_KEYPAIR', 'name': 'test'}

        httpretty.register_uri(httpretty.GET, self.url(),
                               body=jsonutils.dumps({'keypairs': [keypair]}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.GET, self.url('test'),
                               body=jsonutils.dumps({'keypair': keypair}),
                               content_type='application/json')

        httpretty.register_uri(httpretty.DELETE, self.url('test'), status=202)

        def post_os_keypairs(request, url, headers):
            body = jsonutils.loads(request.body.decode('utf-8'))
            assert list(body) == ['keypair']
            fakes.assert_has_keys(body['keypair'], required=['name'])
            return 202, headers, jsonutils.dumps({'keypair': keypair})

        httpretty.register_uri(httpretty.POST, self.url(),
                               body=post_os_keypairs,
                               content_type='application/json')
Exemplo n.º 43
0
    def setUp(self):
        super(V3, self).setUp()

        get_detail = {
            'quota_set': {
                'cores': {'reserved': 0, 'in_use': 0, 'limit': 10},
                'instances': {'reserved': 0, 'in_use': 4, 'limit': 50},
                'ram': {'reserved': 0, 'in_use': 1024, 'limit': 51200}
            }
        }

        httpretty.register_uri(httpretty.GET, self.url('test', 'detail'),
                               body=jsonutils.dumps(get_detail),
                               content_type='application/json')
Exemplo n.º 44
0
    def setUp(self):
        super(PoolsFixture, self).setUp()

        get_os_floating_ip_pools = {
            'floating_ip_pools': [{
                'name': 'foo'
            }, {
                'name': 'bar'
            }]
        }
        httpretty.register_uri(httpretty.GET,
                               self.url(),
                               body=jsonutils.dumps(get_os_floating_ip_pools),
                               content_type='application/json')
Exemplo n.º 45
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_certificate = {
            'certificate': {
                'private_key': None,
                'data': 'foo'
            }
        }
        httpretty.register_uri(httpretty.GET,
                               self.url('root'),
                               body=jsonutils.dumps(get_os_certificate),
                               content_type='application/json')

        post_os_certificates = {
            'certificate': {
                'private_key': 'foo',
                'data': 'bar'
            }
        }
        httpretty.register_uri(httpretty.POST,
                               self.url(),
                               body=jsonutils.dumps(post_os_certificates),
                               content_type='application/json')
Exemplo n.º 46
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.º 47
0
    def setUp(self):
        super(V1, self).setUp()

        uuid = '97f4c221-bff4-4578-b030-0df4ef119353'
        uuid2 = '97f4c221bff44578b0300df4ef119353'
        test_json = jsonutils.dumps({'quota_set': self.test_quota('test')})

        for u in ('test', 'tenant-id', 'tenant-id/defaults',
                  '%s/defaults' % uuid2):
            httpretty.register_uri(httpretty.GET,
                                   self.url(u),
                                   body=test_json,
                                   content_type='application/json')

        quota_json = jsonutils.dumps({'quota_set': self.test_quota(uuid)})
        httpretty.register_uri(httpretty.PUT,
                               self.url(uuid),
                               body=quota_json,
                               content_type='application/json')
        httpretty.register_uri(httpretty.GET,
                               self.url(uuid),
                               body=quota_json,
                               content_type='application/json')

        quota_json2 = jsonutils.dumps({'quota_set': self.test_quota(uuid2)})
        httpretty.register_uri(httpretty.PUT,
                               self.url(uuid2),
                               body=quota_json2,
                               content_type='application/json')
        httpretty.register_uri(httpretty.GET,
                               self.url(uuid2),
                               body=quota_json2,
                               content_type='application/json')

        for u in ('test', uuid2):
            httpretty.register_uri(httpretty.DELETE, self.url(u), status=202)
Exemplo n.º 48
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_fixed_ips = {
            "fixed_ip": {"cidr": "192.168.1.0/24", "address": "192.168.1.1", "hostname": "foo", "host": "bar"}
        }
        httpretty.register_uri(
            httpretty.GET,
            self.url("192.168.1.1"),
            body=jsonutils.dumps(get_os_fixed_ips),
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.POST, self.url("192.168.1.1", "action"), content_type="application/json", status=202
        )
Exemplo n.º 49
0
        def get_os_hosts(request, url, headers):
            host, query = parse.splitquery(url)
            zone = "nova1"

            if query:
                qs = parse.parse_qs(query)
                try:
                    zone = qs["zone"][0]
                except Exception:
                    pass

            data = {
                "hosts": [
                    {"host": "host1", "service": "nova-compute", "zone": zone},
                    {"host": "host1", "service": "nova-cert", "zone": zone},
                ]
            }
            return 200, headers, jsonutils.dumps(data)
Exemplo n.º 50
0
    def setUp(self):
        super(Fixture, self).setUp()

        get_os_fixed_ips = {
            "fixed_ip": {
                'cidr': '192.168.1.0/24',
                'address': '192.168.1.1',
                'hostname': 'foo',
                'host': 'bar'
            }
        }
        httpretty.register_uri(httpretty.GET, self.url('192.168.1.1'),
                               body=jsonutils.dumps(get_os_fixed_ips),
                               content_type='application/json')

        httpretty.register_uri(httpretty.POST,
                               self.url('192.168.1.1', 'action'),
                               content_type='application/json',
                               status=202)
Exemplo n.º 51
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.º 52
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.º 53
0
        def get_os_hosts(request, url, headers):
            host, query = parse.splitquery(url)
            zone = 'nova1'

            if query:
                qs = parse.parse_qs(query)
                try:
                    zone = qs['zone'][0]
                except Exception:
                    pass

            data = {
                'hosts': [{
                    'host': 'host1',
                    'service': 'nova-compute',
                    'zone': zone
                }, {
                    'host': 'host1',
                    'service': 'nova-cert',
                    'zone': zone
                }]
            }
            return 200, headers, jsonutils.dumps(data)
Exemplo n.º 54
0
    def post_servers_1234_action(self, request, url, headers):
        resp = 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.decode('utf-8'))
        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
            resp = 204
        elif action == 'create_image':
            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 resp, headers, jsonutils.dumps(_body)
Exemplo n.º 55
0
 def post_servers_1234_action(self, request, url, headers):
     _body = ''
     body = jsonutils.loads(request.body.decode('utf-8'))
     resp = 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
         return 204, headers, ''
     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'])
         headers['location'] = "http://blah/images/456"
     elif action == 'changePassword':
         assert list(body[action]) == ['adminPass']
     elif action == 'os-getConsoleOutput':
         assert list(body[action]) == ['length']
         return 202, headers, jsonutils.dumps({'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 resp, headers, jsonutils.dumps({'server': _body})
Exemplo n.º 56
0
    def setUp(self):
        super(BaseFixture, self).setUp()

        get_os_hosts_host = {
            "host": [
                {"resource": {"project": "(total)", "host": "dummy", "cpu": 16, "memory_mb": 32234, "disk_gb": 128}},
                {"resource": {"project": "(used_now)", "host": "dummy", "cpu": 1, "memory_mb": 2075, "disk_gb": 45}},
                {"resource": {"project": "(used_max)", "host": "dummy", "cpu": 1, "memory_mb": 2048, "disk_gb": 30}},
                {"resource": {"project": "admin", "host": "dummy", "cpu": 1, "memory_mb": 2048, "disk_gb": 30}},
            ]
        }
        httpretty.register_uri(
            httpretty.GET, self.url("host"), body=jsonutils.dumps(get_os_hosts_host), content_type="application/json"
        )

        def get_os_hosts(request, url, headers):
            host, query = parse.splitquery(url)
            zone = "nova1"

            if query:
                qs = parse.parse_qs(query)
                try:
                    zone = qs["zone"][0]
                except Exception:
                    pass

            data = {
                "hosts": [
                    {"host": "host1", "service": "nova-compute", "zone": zone},
                    {"host": "host1", "service": "nova-cert", "zone": zone},
                ]
            }
            return 200, headers, jsonutils.dumps(data)

        httpretty.register_uri(httpretty.GET, self.url(), body=get_os_hosts, content_type="application/json")

        get_os_hosts_sample_host = {"host": [{"resource": {"host": "sample_host"}}]}
        httpretty.register_uri(
            httpretty.GET,
            self.url("sample_host"),
            body=jsonutils.dumps(get_os_hosts_sample_host),
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.PUT,
            self.url("sample_host", 1),
            body=jsonutils.dumps(self.put_host_1()),
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.PUT,
            self.url("sample_host", 2),
            body=jsonutils.dumps(self.put_host_2()),
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.PUT,
            self.url("sample_host", 3),
            body=jsonutils.dumps(self.put_host_3()),
            content_type="application/json",
        )

        url = self.url("sample_host", "reboot")
        httpretty.register_uri(
            httpretty.GET, url, body=jsonutils.dumps(self.get_host_reboot()), content_type="application/json"
        )

        url = self.url("sample_host", "startup")
        httpretty.register_uri(
            httpretty.GET, url, body=jsonutils.dumps(self.get_host_startup()), content_type="application/json"
        )

        url = self.url("sample_host", "shutdown")
        httpretty.register_uri(
            httpretty.GET, url, body=jsonutils.dumps(self.get_host_shutdown()), content_type="application/json"
        )

        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)

        httpretty.register_uri(
            httpretty.PUT, self.url("sample_host"), body=put_os_hosts_sample_host, content_type="application/json"
        )