Example #1
0
    def test_update_chassis(self):
        new_uuid = uuidutils.generate_uuid()

        self.ch['uuid'] = new_uuid
        res = self.dbapi.update_chassis(self.ch['id'], {'uuid': new_uuid})

        self.assertEqual(res['uuid'], new_uuid)
Example #2
0
 def test_delete_chassis_not_found(self):
     uuid = uuidutils.generate_uuid()
     response = self.delete('/chassis/%s' % uuid, expect_errors=True)
     # TODO(yuriyz): change to 404 (bug 1200517)
     self.assertEqual(response.status_int, 500)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #3
0
 def _create_many_test_nodes(self):
     uuids = []
     for i in xrange(1, 6):
         n = self._create_test_node(id=i, uuid=uuidutils.generate_uuid())
         uuids.append(n['uuid'])
     uuids.sort()
     return uuids
Example #4
0
 def _create_many_test_nodes(self):
     uuids = []
     for i in xrange(1, 6):
         n = self._create_test_node(id=i, uuid=uuidutils.generate_uuid())
         uuids.append(n['uuid'])
     uuids.sort()
     return uuids
Example #5
0
    def test_remove_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        pdict = dbutils.get_test_port(extra=extra,
                                      address="AA:BB:CC:DD:EE:FF",
                                      uuid=uuidutils.generate_uuid())
        self.post_json('/ports', pdict)

        # Removing one item from the collection
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/extra/foo2', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/ports/%s' % pdict['uuid'])
        extra.pop("foo2")
        self.assertEqual(result['extra'], extra)

        # Removing the collection
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/extra', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/ports/%s' % pdict['uuid'])
        self.assertEqual(result['extra'], {})

        # Assert nothing else was changed
        self.assertEqual(result['uuid'], pdict['uuid'])
        self.assertEqual(result['address'], pdict['address'])
Example #6
0
    def test_remove_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        cdict = dbutils.get_test_chassis(extra=extra, description="foobar",
                                         uuid=uuidutils.generate_uuid())
        self.post_json('/chassis', cdict)

        # Removing one item from the collection
        response = self.patch_json('/chassis/%s' % cdict['uuid'],
                                   [{'path': '/extra/foo2', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/chassis/%s' % cdict['uuid'])
        extra.pop("foo2")
        self.assertEqual(result['extra'], extra)

        # Removing the collection
        response = self.patch_json('/chassis/%s' % cdict['uuid'],
                                   [{'path': '/extra', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/chassis/%s' % cdict['uuid'])
        self.assertEqual(result['extra'], {})

        # Assert nothing else was changed
        self.assertEqual(result['uuid'], cdict['uuid'])
        self.assertEqual(result['description'], cdict['description'])
Example #7
0
 def test_delete_chassis_not_found(self):
     uuid = uuidutils.generate_uuid()
     response = self.delete('/chassis/%s' % uuid, expect_errors=True)
     # TODO(yuriyz): change to 404 (bug 1200517)
     self.assertEqual(response.status_int, 500)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #8
0
 def test_update_state_in_progress(self):
     ndict = dbutils.get_test_node(id=99, uuid=uuidutils.generate_uuid(),
                                   target_power_state=states.POWER_OFF)
     node = self.dbapi.create_node(ndict)
     self.assertRaises(webtest.app.AppError, self.patch_json,
                       '/nodes/%s' % node['uuid'],
                       [{'path': '/extra/foo', 'value': 'bar',
                         'op': 'add'}])
Example #9
0
    def test_update_chassis(self):
        ch = self._create_test_chassis()
        new_uuid = uuidutils.generate_uuid()

        ch['uuid'] = new_uuid
        res = self.dbapi.update_chassis(ch['id'], {'uuid': new_uuid})

        self.assertEqual(res['uuid'], new_uuid)
Example #10
0
def create_fake_node(i):
    dbh = dbapi.get_instance()
    node = utils.get_test_node(id=i,
                               uuid=uuidutils.generate_uuid(),
                               control_driver='fake',
                               deploy_driver='fake')
    dbh.create_node(node)
    return node['uuid']
Example #11
0
 def test_update_not_found(self):
     uuid = uuidutils.generate_uuid()
     response = self.patch_json('/ports/%s' % uuid, {'extra': {'a': 'b'}},
                                expect_errors=True)
     # TODO(yuriyz): change to 404 (bug 1200517)
     self.assertEqual(response.status_int, 500)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #12
0
 def test_links(self):
     uuid = uuidutils.generate_uuid()
     ndict = dbutils.get_test_chassis(id=1, uuid=uuid)
     self.dbapi.create_chassis(ndict)
     data = self.get_json('/chassis/1')
     self.assertIn('links', data.keys())
     self.assertEqual(len(data['links']), 2)
     self.assertIn(uuid, data['links'][0]['href'])
Example #13
0
 def test_links(self):
     uuid = uuidutils.generate_uuid()
     ndict = dbutils.get_test_node(id=1, uuid=uuid)
     self.dbapi.create_node(ndict)
     data = self.get_json('/nodes/1')
     self.assertIn('links', data.keys())
     self.assertEqual(len(data['links']), 2)
     self.assertIn(uuid, data['links'][0]['href'])
Example #14
0
 def create_port(self, values):
     if not values.get('uuid'):
         values['uuid'] = uuidutils.generate_uuid()
     if not values.get('extra'):
         values['extra'] = '{}'
     port = models.Port()
     port.update(values)
     port.save()
     return port
Example #15
0
 def create_chassis(self, values):
     if not values.get('uuid'):
         values['uuid'] = uuidutils.generate_uuid()
     if not values.get('extra'):
         values['extra'] = '{}'
     chassis = models.Chassis()
     chassis.update(values)
     chassis.save()
     return chassis
Example #16
0
 def test_update_not_found(self):
     uuid = uuidutils.generate_uuid()
     response = self.patch_json('/chassis/%s' % uuid,
                                [{'path': '/extra/a', 'value': 'b',
                                  'op': 'add'}],
                                expect_errors=True)
     self.assertEqual(response.status_int, 404)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #17
0
 def create_chassis(self, values):
     if not values.get("uuid"):
         values["uuid"] = uuidutils.generate_uuid()
     if not values.get("extra"):
         values["extra"] = "{}"
     chassis = models.Chassis()
     chassis.update(values)
     chassis.save()
     return chassis
Example #18
0
 def create_port(self, values):
     if not values.get("uuid"):
         values["uuid"] = uuidutils.generate_uuid()
     if not values.get("extra"):
         values["extra"] = "{}"
     port = models.Port()
     port.update(values)
     port.save()
     return port
Example #19
0
 def create_chassis(self, values):
     if not values.get('uuid'):
         values['uuid'] = uuidutils.generate_uuid()
     if not values.get('extra'):
         values['extra'] = '{}'
     chassis = models.Chassis()
     chassis.update(values)
     chassis.save()
     return chassis
Example #20
0
 def test_get_node_list(self):
     uuids = []
     for i in xrange(1, 6):
         n = utils.get_test_node(id=i, uuid=uuidutils.generate_uuid())
         self.dbapi.create_node(n)
         uuids.append(unicode(n['uuid']))
     res = self.dbapi.get_node_list()
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Example #21
0
 def test_get_node_list(self):
     uuids = []
     for i in xrange(1, 6):
         n = utils.get_test_node(id=i, uuid=uuidutils.generate_uuid())
         self.dbapi.create_node(n)
         uuids.append(unicode(n['uuid']))
     res = self.dbapi.get_node_list()
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Example #22
0
 def create_port(self, values):
     if not values.get('uuid'):
         values['uuid'] = uuidutils.generate_uuid()
     if not values.get('extra'):
         values['extra'] = '{}'
     port = models.Port()
     port.update(values)
     port.save()
     return port
Example #23
0
 def test_update_not_found(self):
     uuid = uuidutils.generate_uuid()
     response = self.patch_json('/ports/%s' % uuid, {'extra': {
         'a': 'b'
     }},
                                expect_errors=True)
     # TODO(yuriyz): change to 404 (bug 1200517)
     self.assertEqual(response.status_int, 500)
     self.assertEqual(response.content_type, 'application/json')
     self.assertTrue(response.json['error_message'])
Example #24
0
 def test_remove_mandatory_field(self):
     pdict = dbutils.get_test_port(address="AA:BB:CC:DD:EE:FF",
                                   uuid=uuidutils.generate_uuid())
     self.post_json('/ports', pdict)
     response = self.patch_json('/ports/%s' % pdict['uuid'],
                                [{'path': '/address', 'op': 'remove'}],
                                expect_errors=True)
     self.assertEqual(response.content_type, 'application/json')
     self.assertEqual(response.status_code, 400)
     self.assertTrue(response.json['error_message'])
Example #25
0
 def test_links(self):
     uuid = uuidutils.generate_uuid()
     ndict = dbutils.get_test_port(id=1, uuid=uuid)
     self.dbapi.create_port(ndict)
     data = self.get_json('/ports/1')
     self.assertIn('links', data.keys())
     self.assertEqual(len(data['links']), 2)
     self.assertIn(uuid, data['links'][0]['href'])
     self.assertTrue(self.validate_link(data['links'][0]['href']))
     self.assertTrue(self.validate_link(data['links'][1]['href']))
Example #26
0
 def test_get_port_list(self):
     uuids = []
     for i in xrange(1, 6):
         n = utils.get_test_port(id=i, uuid=uuidutils.generate_uuid())
         self.dbapi.create_port(n)
         uuids.append(unicode(n['uuid']))
     res = self.dbapi.get_port_list()
     uuids.sort()
     res.sort()
     self.assertEqual(uuids, res)
Example #27
0
    def test_collection_links(self):
        chassis = []
        for id in xrange(5):
            ndict = dbutils.get_test_chassis(id=id,
                                             uuid=uuidutils.generate_uuid())
            ch = self.dbapi.create_chassis(ndict)
            chassis.append(ch['uuid'])
        data = self.get_json('/chassis/?limit=3')
        self.assertEqual(len(data['chassis']), 3)

        next_marker = data['chassis'][-1]['uuid']
        self.assertIn(next_marker, data['next'])
Example #28
0
    def test_many(self):
        ch_list = []
        for id in xrange(5):
            ndict = dbutils.get_test_chassis(id=id,
                                             uuid=uuidutils.generate_uuid())
            chassis = self.dbapi.create_chassis(ndict)
            ch_list.append(chassis['uuid'])
        data = self.get_json('/chassis')
        self.assertEqual(len(ch_list), len(data['items']))

        uuids = [n['uuid'] for n in data['items']]
        self.assertEqual(ch_list.sort(), uuids.sort())
Example #29
0
    def test_collection_links(self):
        nodes = []
        for id in xrange(5):
            ndict = dbutils.get_test_node(id=id,
                                          uuid=uuidutils.generate_uuid())
            node = self.dbapi.create_node(ndict)
            nodes.append(node['uuid'])
        data = self.get_json('/nodes/?limit=3')
        self.assertEqual(len(data['nodes']), 3)

        next_marker = data['nodes'][-1]['uuid']
        self.assertIn(next_marker, data['next'])
Example #30
0
    def _create_associated_nodes(self):
        uuids = []
        uuids_with_instance = []

        for i in xrange(1, 5):
            uuid = uuidutils.generate_uuid()
            uuids.append(unicode(uuid))
            if i < 3:
                instance_uuid = uuidutils.generate_uuid()
                uuids_with_instance.append(unicode(uuid))
            else:
                instance_uuid = None

            n = utils.get_test_node(id=i,
                                    uuid=uuid,
                                    instance_uuid=instance_uuid)
            self.dbapi.create_node(n)

        uuids.sort()
        uuids_with_instance.sort()
        return (uuids, uuids_with_instance)
Example #31
0
    def test_many(self):
        ports = []
        for id in xrange(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=uuidutils.generate_uuid())
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports')
        self.assertEqual(len(ports), len(data['items']))

        uuids = [n['uuid'] for n in data['items']]
        self.assertEqual(ports.sort(), uuids.sort())
Example #32
0
    def test_collection_links(self):
        ports = []
        for id in xrange(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=uuidutils.generate_uuid())
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports/?limit=3')
        self.assertEqual(len(data['ports']), 3)

        next_marker = data['ports'][-1]['uuid']
        self.assertIn(next_marker, data['next'])
Example #33
0
    def test_many(self):
        ch_list = []
        for id in xrange(5):
            ndict = dbutils.get_test_chassis(id=id,
                                             uuid=uuidutils.generate_uuid())
            chassis = self.dbapi.create_chassis(ndict)
            ch_list.append(chassis['uuid'])
        data = self.get_json('/chassis')
        self.assertEqual(len(ch_list), len(data['items']))

        uuids = [n['uuid'] for n in data['items']]
        self.assertEqual(ch_list.sort(), uuids.sort())
Example #34
0
    def test_many(self):
        ports = []
        for id in xrange(5):
            ndict = dbutils.get_test_port(id=id,
                                          uuid=uuidutils.generate_uuid())
            port = self.dbapi.create_port(ndict)
            ports.append(port['uuid'])
        data = self.get_json('/ports')
        self.assertEqual(len(ports), len(data['ports']))

        uuids = [n['uuid'] for n in data['ports']]
        self.assertEqual(ports.sort(), uuids.sort())
Example #35
0
    def test_many(self):
        nodes = []
        for id in xrange(5):
            ndict = dbutils.get_test_node(id=id,
                                          uuid=uuidutils.generate_uuid())
            node = self.dbapi.create_node(ndict)
            nodes.append(node['uuid'])
        data = self.get_json('/nodes')
        self.assertEqual(len(nodes), len(data['items']))

        uuids = [n['uuid'] for n in data['items']]
        self.assertEqual(nodes.sort(), uuids.sort())
Example #36
0
    def test_many(self):
        nodes = []
        for id in xrange(5):
            ndict = dbutils.get_test_node(id=id,
                                          uuid=uuidutils.generate_uuid())
            node = self.dbapi.create_node(ndict)
            nodes.append(node['uuid'])
        data = self.get_json('/nodes')
        self.assertEqual(len(nodes), len(data['nodes']))

        uuids = [n['uuid'] for n in data['nodes']]
        self.assertEqual(nodes.sort(), uuids.sort())
Example #37
0
 def test_refresh(self):
     uuid = self.fake_chassis['uuid']
     new_uuid = uuidutils.generate_uuid()
     returns = [dict(self.fake_chassis, uuid=uuid),
                dict(self.fake_chassis, uuid=new_uuid)]
     expected = [mock.call(uuid), mock.call(uuid)]
     with mock.patch.object(self.dbapi, 'get_chassis', side_effect=returns,
                            autospec=True) as mock_get_chassis:
         c = objects.Chassis.get_by_uuid(self.context, uuid)
         self.assertEqual(c.uuid, uuid)
         c.refresh()
         self.assertEqual(c.uuid, new_uuid)
         self.assertEqual(mock_get_chassis.call_args_list, expected)
Example #38
0
    def test_replace_address_already_exist(self):
        address = '11:22:33:AA:BB:CC'
        pdict = dbutils.get_test_port(address=address,
                                      uuid=uuidutils.generate_uuid())
        self.post_json('/ports', pdict)

        pdict = dbutils.get_test_port()
        response = self.patch_json('/ports/%s' % pdict['uuid'],
                                   [{'path': '/address',
                                     'value': address, 'op': 'replace'}],
                                     expect_errors=True)
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 400)
        self.assertTrue(response.json['error_message'])
Example #39
0
    def test_collection_links(self):
        chassis = []
        for id in xrange(5):
            ndict = dbutils.get_test_chassis(id=id,
                                             uuid=uuidutils.generate_uuid())
            ch = self.dbapi.create_chassis(ndict)
            chassis.append(ch['uuid'])
        data = self.get_json('/chassis/?limit=3')
        self.assertEqual(data['type'], 'chassis')
        self.assertEqual(len(data['items']), 3)

        next_marker = data['items'][-1]['uuid']
        next_link = [l['href'] for l in data['links'] if l['rel'] == 'next'][0]
        self.assertIn(next_marker, next_link)
Example #40
0
    def test_collection_links(self):
        nodes = []
        for id in xrange(5):
            ndict = dbutils.get_test_node(id=id,
                                          uuid=uuidutils.generate_uuid())
            node = self.dbapi.create_node(ndict)
            nodes.append(node['uuid'])
        data = self.get_json('/nodes/?limit=3')
        self.assertEqual(data['type'], 'node')
        self.assertEqual(len(data['items']), 3)

        next_marker = data['items'][-1]['uuid']
        next_link = [l['href'] for l in data['links'] if l['rel'] == 'next'][0]
        self.assertIn(next_marker, next_link)
Example #41
0
    def test_remove_singular(self):
        cdict = dbutils.get_test_chassis(extra={'a': 'b'},
                                         uuid=uuidutils.generate_uuid())
        self.post_json('/chassis', cdict)
        response = self.patch_json('/chassis/%s' % cdict['uuid'],
                                   [{'path': '/description', 'op': 'remove'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/chassis/%s' % cdict['uuid'])
        self.assertEqual(result['description'], None)

        # Assert nothing else was changed
        self.assertEqual(result['uuid'], cdict['uuid'])
        self.assertEqual(result['extra'], cdict['extra'])
Example #42
0
    def test_replace_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        cdict = dbutils.get_test_chassis(extra=extra,
                                         uuid=uuidutils.generate_uuid())
        self.post_json('/chassis', cdict)
        new_value = 'new value'
        response = self.patch_json('/chassis/%s' % cdict['uuid'],
                                   [{'path': '/extra/foo2',
                                     'value': new_value, 'op': 'replace'}])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
        result = self.get_json('/chassis/%s' % cdict['uuid'])

        extra["foo2"] = new_value
        self.assertEqual(result['extra'], extra)
Example #43
0
    def create_node(self, values):
        # ensure defaults are present for new nodes
        if not values.get('uuid'):
            values['uuid'] = uuidutils.generate_uuid()
        if not values.get('task_state'):
            values['task_state'] = states.NOSTATE
        if not values.get('properties'):
            values['properties'] = '{}'
        if not values.get('extra'):
            values['extra'] = '{}'
        if not values.get('driver_info'):
            values['driver_info'] = '{}'

        node = models.Node()
        node.update(values)
        node.save()
        return node
Example #44
0
    def test_refresh(self):
        uuid = self.fake_chassis['uuid']
        new_uuid = uuidutils.generate_uuid()

        self.mox.StubOutWithMock(self.dbapi, 'get_chassis')

        self.dbapi.get_chassis(uuid).AndReturn(
                dict(self.fake_chassis, uuid=uuid))
        self.dbapi.get_chassis(uuid).AndReturn(
                dict(self.fake_chassis, uuid=new_uuid))
        self.mox.ReplayAll()

        c = objects.Chassis.get_by_uuid(self.context, uuid)
        self.assertEqual(c.uuid, uuid)
        c.refresh()
        self.assertEqual(c.uuid, new_uuid)
        self.mox.VerifyAll()
Example #45
0
    def test_ports_subresource(self):
        ndict = dbutils.get_test_node()
        self.dbapi.create_node(ndict)

        for id in xrange(2):
            pdict = dbutils.get_test_port(id=id,
                                          node_id=ndict['id'],
                                          uuid=uuidutils.generate_uuid())
            self.dbapi.create_port(pdict)

        data = self.get_json('/nodes/%s/ports' % ndict['uuid'])
        self.assertEqual(data['type'], 'port')
        self.assertEqual(len(data['items']), 2)
        self.assertEqual(len(data['links']), 0)

        # Test collection pagination
        data = self.get_json('/nodes/%s/ports?limit=1' % ndict['uuid'])
        self.assertEqual(data['type'], 'port')
        self.assertEqual(len(data['items']), 1)
        self.assertEqual(len(data['links']), 1)
Example #46
0
    def test_nodes_subresource(self):
        cdict = dbutils.get_test_chassis()
        self.dbapi.create_chassis(cdict)

        for id in xrange(2):
            ndict = dbutils.get_test_node(id=id,
                                          chassis_id=cdict['id'],
                                          uuid=uuidutils.generate_uuid())
            self.dbapi.create_node(ndict)

        data = self.get_json('/chassis/%s/nodes' % cdict['uuid'])
        self.assertEqual(data['type'], 'node')
        self.assertEqual(len(data['items']), 2)
        self.assertEqual(len(data['links']), 0)

        # Test collection pagination
        data = self.get_json('/chassis/%s/nodes?limit=1' % cdict['uuid'])
        self.assertEqual(data['type'], 'node')
        self.assertEqual(len(data['items']), 1)
        self.assertEqual(len(data['links']), 1)
Example #47
0
    def test_update_chassis_that_does_not_exist(self):
        new_uuid = uuidutils.generate_uuid()

        self.assertRaises(exception.ChassisNotFound, self.dbapi.update_chassis,
                          666, {'uuid': new_uuid})
Example #48
0
def create_fake_node(i):
    dbh = dbapi.get_instance()
    node = utils.get_test_node(id=i, uuid=uuidutils.generate_uuid())
    dbh.create_node(node)
    return node['uuid']
Example #49
0
def generate_request_id():
    return 'req-%s' % uuidutils.generate_uuid()