Ejemplo n.º 1
0
    def test_find_suitable_baremetal_node_about_cpu(self):
        n1 = utils.new_bm_node(id=1, cpus=1, memory_mb=512,
                               service_host="host1")
        n2 = utils.new_bm_node(id=2, cpus=2, memory_mb=512,
                               service_host="host1")
        n3 = utils.new_bm_node(id=3, cpus=3, memory_mb=512,
                               service_host="host1")
        nodes = [n1, n2, n3]
        self.stubs.Set(bm_driver, '_get_baremetal_nodes', lambda self: nodes)
        inst = {'memory_mb': 512}

        inst['vcpus'] = 1
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 1)

        inst['vcpus'] = 2
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 2)

        inst['vcpus'] = 3
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 3)

        inst['vcpus'] = 4
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertTrue(result is None)
Ejemplo n.º 2
0
    def test_find_suitable_baremetal_node_about_memory(self):
        h1 = utils.new_bm_node(id=1, memory_mb=512, service_host="host1")
        h2 = utils.new_bm_node(id=2, memory_mb=2048, service_host="host1")
        h3 = utils.new_bm_node(id=3, memory_mb=1024, service_host="host1")
        hosts = [h1, h2, h3]
        self.stubs.Set(bm_driver, '_get_baremetal_nodes', lambda self: hosts)
        inst = {'vcpus': 1}

        inst['memory_mb'] = 1
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 1)

        inst['memory_mb'] = 512
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 1)

        inst['memory_mb'] = 513
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 3)

        inst['memory_mb'] = 1024
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 3)

        inst['memory_mb'] = 1025
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 2)

        inst['memory_mb'] = 2048
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertEqual(result['id'], 2)

        inst['memory_mb'] = 2049
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.assertTrue(result is None)
Ejemplo n.º 3
0
    def test_get_power_manager(self):
        n1 = utils.new_bm_node(
                pm_address='10.1.1.1',
                id='1')
        pm1 = tilera_pdu.Pdu(n1)
        self.assertEqual(pm1._address, '10.1.1.1')
        self.assertEqual(pm1._node_id, '1')

        n2 = utils.new_bm_node(
                pm_address='10.2.2.2',
                id='2')
        pm2 = tilera_pdu.Pdu(n2)
        self.assertEqual(pm2._address, '10.2.2.2')
        self.assertEqual(pm2._node_id, '2')
Ejemplo n.º 4
0
    def test_find_suitable_baremetal_node_verify(self):
        n1 = utils.new_bm_node(id=1, memory_mb=512, service_host="host1")
        n2 = utils.new_bm_node(id=2, memory_mb=2048, service_host="host1")
        n3 = utils.new_bm_node(id=3, memory_mb=1024, service_host="host1")
        hosts = [n1, n2, n3]
        inst = {}
        inst['vcpus'] = 1
        inst['memory_mb'] = 1024

        self.mox.StubOutWithMock(bm_driver, '_get_baremetal_nodes')
        bm_driver._get_baremetal_nodes("context").AndReturn(hosts)
        self.mox.ReplayAll()
        result = bm_driver._find_suitable_baremetal_node("context", inst)
        self.mox.VerifyAll()
        self.assertEqual(result['id'], 3)
Ejemplo n.º 5
0
    def test_ipmi(self):
        n1 = utils.new_bm_node(pm_address='10.1.1.1',
                               pm_user='******',
                               pm_password='******')
        pm1 = ipmi.Ipmi(n1)
        self.assertEqual(pm1._address, '10.1.1.1')
        self.assertEqual(pm1._user, 'n1_user')
        self.assertEqual(pm1._password, 'n1_password')

        n2 = utils.new_bm_node(pm_address='10.2.2.2',
                               pm_user='******',
                               pm_password='******')
        pm2 = ipmi.Ipmi(n2)
        self.assertEqual(pm2._address, '10.2.2.2')
        self.assertEqual(pm2._user, 'n2_user')
        self.assertEqual(pm2._password, 'n2_password')
Ejemplo n.º 6
0
    def setUp(self):
        super(BareMetalTileraTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = tilera.Tilera(fake_virt.FakeVirtAPI())

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
            service_host='test_host',
            cpus=4,
            memory_mb=2048,
            prov_mac_address='11:11:11:11:11:11',
        )
        self.nic_info = [
            {
                'address': '22:22:22:22:22:22',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '33:33:33:33:33:33',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
Ejemplo n.º 7
0
    def test_exec_ipmitool(self):
        H = 'address'
        U = 'user'
        P = 'password'
        I = 'lanplus'
        F = 'password_file'

        n1 = utils.new_bm_node(pm_address=H, pm_user=U, pm_password=P)

        self.mox.StubOutWithMock(ipmi, '_make_password_file')
        self.mox.StubOutWithMock(nova_utils, 'execute')
        self.mox.StubOutWithMock(ipmi, '_unlink_without_raise')
        ipmi._make_password_file(P).AndReturn(F)
        args = [
            'ipmitool',
            '-I',
            I,
            '-H',
            H,
            '-U',
            U,
            '-f',
            F,
            'A',
            'B',
            'C',
        ]
        nova_utils.execute(*args, attempts=3).AndReturn(('', ''))
        ipmi._unlink_without_raise(F).AndReturn(None)
        self.mox.ReplayAll()

        i = ipmi.Ipmi(n1)
        i._exec_ipmitool('A B C')
        self.mox.VerifyAll()
Ejemplo n.º 8
0
 def setUp(self):
     super(BareMetalIPMITestCase, self).setUp()
     self.node = bm_db_utils.new_bm_node(id=123,
                                         pm_address='fake-address',
                                         pm_user='******',
                                         pm_password='******')
     self.ipmi = ipmi.IPMI(self.node)
Ejemplo n.º 9
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(None)
        self.node_info = bm_db_utils.new_bm_node(
            id=123,
            service_host='test_host',
            cpus=2,
            memory_mb=2048,
        )
        self.nic_info = [
            {
                'address': '01:23:45:67:89:01',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '01:23:45:67:89:02',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
        self.addCleanup(fake_image.FakeImageService_reset)
Ejemplo n.º 10
0
    def setUp(self):
        super(BareMetalVPDTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
            id=123,
            service_host='test_host',
            cpus=2,
            memory_mb=2048,
        )
        self.nic_info = [
            {
                'address': '11:11:11:11:11:11',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': '22:22:22:22:22:22',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
        self.addCleanup(fake_image.FakeImageService_reset)
Ejemplo n.º 11
0
    def test_exec_ipmitool(self):
        H = 'address'
        U = 'user'
        P = 'password'
        I = 'lanplus'
        F = 'password_file'

        n1 = utils.new_bm_node(
                pm_address=H,
                pm_user=U,
                pm_password=P)

        self.mox.StubOutWithMock(ipmi, '_make_password_file')
        self.mox.StubOutWithMock(nova_utils, 'execute')
        self.mox.StubOutWithMock(ipmi, '_unlink_without_raise')
        ipmi._make_password_file(P).AndReturn(F)
        args = [
                'ipmitool',
                '-I', I,
                '-H', H,
                '-U', U,
                '-f', F,
                'A', 'B', 'C',
                ]
        nova_utils.execute(*args, attempts=3).AndReturn(('', ''))
        ipmi._unlink_without_raise(F).AndReturn(None)
        self.mox.ReplayAll()

        i = ipmi.Ipmi(n1)
        i._exec_ipmitool('A B C')
        self.mox.VerifyAll()
Ejemplo n.º 12
0
    def setUp(self):
        super(BareMetalPXETestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)
        self.driver = pxe.PXE()

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
                id=123,
                service_host='test_host',
                cpus=2,
                memory_mb=2048,
                prov_mac_address='11:11:11:11:11:11',
            )
        self.nic_info = [
                {'address': '22:22:22:22:22:22', 'datapath_id': '0x1',
                    'port_no': 1},
                {'address': '33:33:33:33:33:33', 'datapath_id': '0x2',
                    'port_no': 2},
            ]
Ejemplo n.º 13
0
 def setUp(self):
     super(BareMetalIPMITestCase, self).setUp()
     self.node = bm_db_utils.new_bm_node(
             id=123,
             pm_address='fake-address',
             pm_user='******',
             pm_password='******')
     self.ipmi = ipmi.IPMI(self.node)
Ejemplo n.º 14
0
    def test_ipmi(self):
        n1 = utils.new_bm_node(
                pm_address='10.1.1.1',
                pm_user='******',
                pm_password='******')
        pm1 = ipmi.Ipmi(n1)
        self.assertEqual(pm1._address, '10.1.1.1')
        self.assertEqual(pm1._user, 'n1_user')
        self.assertEqual(pm1._password, 'n1_password')

        n2 = utils.new_bm_node(
                pm_address='10.2.2.2',
                pm_user='******',
                pm_password='******')
        pm2 = ipmi.Ipmi(n2)
        self.assertEqual(pm2._address, '10.2.2.2')
        self.assertEqual(pm2._user, 'n2_user')
        self.assertEqual(pm2._password, 'n2_password')
Ejemplo n.º 15
0
 def setUp(self):
     super(BareMetalPduTestCase, self).setUp()
     self.node = bm_db_utils.new_bm_node(
             id=123,
             pm_address='fake-address',
             pm_user='******',
             pm_password='******')
     self.tilera_pdu = tilera_pdu.Pdu(self.node)
     self.tile_pdu_on = 1
     self.tile_pdu_off = 2
     self.tile_pdu_status = 9
Ejemplo n.º 16
0
    def _create_node(self, node_info=None, nic_info=None):
        result = {}
        if node_info is None:
            node_info = bm_db_utils.new_bm_node(
                id=123,
                service_host='test_host',
                cpus=2,
                memory_mb=2048,
            )
        if nic_info is None:
            nic_info = [
                {
                    'address': '01:23:45:67:89:01',
                    'datapath_id': '0x1',
                    'port_no': 1
                },
                {
                    'address': '01:23:45:67:89:02',
                    'datapath_id': '0x2',
                    'port_no': 2
                },
            ]
        result['node_info'] = node_info
        result['nic_info'] = nic_info
        result['node'] = db.bm_node_create(self.context, node_info)

        for nic in nic_info:
            db.bm_interface_create(
                self.context,
                result['node']['id'],
                nic['address'],
                nic['datapath_id'],
                nic['port_no'],
            )
        result['instance'] = utils.get_test_instance()
        result['instance']['node'] = result['node']['uuid']
        result['spawn_params'] = dict(
            admin_password='******',
            block_device_info=None,
            context=self.context,
            image_meta=utils.get_test_image_info(None, result['instance']),
            injected_files=[('/fake/path', 'hello world')],
            instance=result['instance'],
            network_info=utils.get_test_network_info(),
        )
        result['destroy_params'] = dict(
            instance=result['instance'],
            network_info=result['spawn_params']['network_info'],
            block_device_info=result['spawn_params']['block_device_info'],
        )

        return result
Ejemplo n.º 17
0
    def _create_node(self, node_info=None, nic_info=None):
        result = {}
        if node_info is None:
            node_info = bm_db_utils.new_bm_node(
                            id=123,
                            service_host='test_host',
                            cpus=2,
                            memory_mb=2048,
                        )
        if nic_info is None:
            nic_info = [
                    {'address': '01:23:45:67:89:01', 'datapath_id': '0x1',
                        'port_no': 1},
                    {'address': '01:23:45:67:89:02', 'datapath_id': '0x2',
                        'port_no': 2},
                ]
        result['node_info'] = node_info
        result['nic_info'] = nic_info
        result['node'] = db.bm_node_create(self.context, node_info)

        for nic in nic_info:
            db.bm_interface_create(
                                    self.context,
                                    result['node']['id'],
                                    nic['address'],
                                    nic['datapath_id'],
                                    nic['port_no'],
                )
        result['instance'] = utils.get_test_instance()
        result['instance']['node'] = result['node']['uuid']
        result['spawn_params'] = dict(
                admin_password='******',
                block_device_info=None,
                context=self.context,
                image_meta=utils.get_test_image_info(
                                None, result['instance']),
                injected_files=[('/fake/path', 'hello world')],
                instance=result['instance'],
                network_info=utils.get_test_network_info(),
            )
        result['destroy_params'] = dict(
                instance=result['instance'],
                network_info=result['spawn_params']['network_info'],
                block_device_info=result['spawn_params']['block_device_info'],
            )

        return result
Ejemplo n.º 18
0
    def test_get_available_nodes(self):
        self.assertEqual(0, len(self.driver.get_available_nodes()))

        node1 = self._create_node()
        self.assertEqual(1, len(self.driver.get_available_nodes()))

        node_info = bm_db_utils.new_bm_node(
            id=456,
            service_host='test_host',
            cpus=2,
            memory_mb=2048,
        )
        nic_info = [
            {
                'address': 'cc:cc:cc',
                'datapath_id': '0x1',
                'port_no': 1
            },
            {
                'address': 'dd:dd:dd',
                'datapath_id': '0x2',
                'port_no': 2
            },
        ]
        node2 = self._create_node(node_info=node_info, nic_info=nic_info)
        self.assertEqual(2, len(self.driver.get_available_nodes()))
        self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
                         self.driver.get_available_nodes())

        node1['instance']['hostname'] = 'test-host-1'
        node2['instance']['hostname'] = 'test-host-2'

        self.driver.spawn(**node1['spawn_params'])
        self.assertEqual(1, len(self.driver.get_available_nodes()))

        self.driver.spawn(**node2['spawn_params'])
        self.assertEqual(0, len(self.driver.get_available_nodes()))

        self.driver.destroy(**node1['destroy_params'])
        self.assertEqual(1, len(self.driver.get_available_nodes()))

        self.driver.destroy(**node2['destroy_params'])
        self.assertEqual(2, len(self.driver.get_available_nodes()))
        self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
                         self.driver.get_available_nodes())
Ejemplo n.º 19
0
    def setUp(self):
        super(BareMetalVPDTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = (None,)
        self.instance = utils.get_test_instance()
        self.test_network_info = (utils.get_test_network_info(),)
        self.node_info = bm_db_utils.new_bm_node(
            id=123, service_host="test_host", cpus=2, memory_mb=2048, prov_mac_address="11:11:11:11:11:11"
        )
        self.nic_info = [
            {"address": "22:22:22:22:22:22", "datapath_id": "0x1", "port_no": 1},
            {"address": "33:33:33:33:33:33", "datapath_id": "0x2", "port_no": 2},
        ]
        self.addCleanup(fake_image.FakeImageService_reset)
Ejemplo n.º 20
0
 def _create_nodes(self):
     nodes = [
         utils.new_bm_node(pm_address="0", service_host="host1", memory_mb=100000, cpus=100, local_gb=10000),
         utils.new_bm_node(
             pm_address="1", service_host="host2", instance_uuid="A", memory_mb=100000, cpus=100, local_gb=10000
         ),
         utils.new_bm_node(pm_address="2", service_host="host2", memory_mb=1000, cpus=1, local_gb=1000),
         utils.new_bm_node(pm_address="3", service_host="host2", memory_mb=1000, cpus=2, local_gb=1000),
         utils.new_bm_node(pm_address="4", service_host="host2", memory_mb=2000, cpus=1, local_gb=1000),
         utils.new_bm_node(pm_address="5", service_host="host2", memory_mb=2000, cpus=2, local_gb=1000),
     ]
     self.ids = []
     for n in nodes:
         ref = db.bm_node_create(self.context, n)
         self.ids.append(ref["id"])
Ejemplo n.º 21
0
    def setUp(self):
        super(BareMetalDriverWithDBTestCase, self).setUp()
        self.flags(**COMMON_FLAGS)
        self.flags(**BAREMETAL_FLAGS)

        fake_image.stub_out_image_service(self.stubs)
        self.context = utils.get_test_admin_context()
        self.driver = bm_driver.BareMetalDriver(None)
        self.node_info = bm_db_utils.new_bm_node(
                id=123,
                service_host='test_host',
                cpus=2,
                memory_mb=2048,
            )
        self.nic_info = [
                {'address': '01:23:45:67:89:01', 'datapath_id': '0x1',
                    'port_no': 1},
                {'address': '01:23:45:67:89:02', 'datapath_id': '0x2',
                    'port_no': 2},
            ]
        self.addCleanup(fake_image.FakeImageService_reset)
Ejemplo n.º 22
0
    def test_get_available_nodes(self):
        self.assertEqual(0, len(self.driver.get_available_nodes()))

        node1 = self._create_node()
        self.assertEqual(1, len(self.driver.get_available_nodes()))

        node_info = bm_db_utils.new_bm_node(
                        id=456,
                        service_host='test_host',
                        cpus=2,
                        memory_mb=2048,
                    )
        nic_info = [
                {'address': 'cc:cc:cc', 'datapath_id': '0x1',
                    'port_no': 1},
                {'address': 'dd:dd:dd', 'datapath_id': '0x2',
                    'port_no': 2},
            ]
        node2 = self._create_node(node_info=node_info, nic_info=nic_info)
        self.assertEqual(2, len(self.driver.get_available_nodes()))
        self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
                         self.driver.get_available_nodes())

        node1['instance']['hostname'] = 'test-host-1'
        node2['instance']['hostname'] = 'test-host-2'

        self.driver.spawn(**node1['spawn_params'])
        self.assertEqual(1, len(self.driver.get_available_nodes()))

        self.driver.spawn(**node2['spawn_params'])
        self.assertEqual(0, len(self.driver.get_available_nodes()))

        self.driver.destroy(**node1['destroy_params'])
        self.assertEqual(1, len(self.driver.get_available_nodes()))

        self.driver.destroy(**node2['destroy_params'])
        self.assertEqual(2, len(self.driver.get_available_nodes()))
        self.assertEqual([node1['node']['uuid'], node2['node']['uuid']],
                         self.driver.get_available_nodes())
Ejemplo n.º 23
0
    def setUp(self):
        super(BareMetalTileraTestCase, self).setUp()
        self.config(**COMMON_CONFIG)
        self.config(**BAREMETAL_CONFIG)
        self.driver = tilera.Tilera(fake_virt.FakeVirtAPI())

        fake_image.stub_out_image_service(self.stubs)
        self.addCleanup(fake_image.FakeImageService_reset)
        self.context = utils.get_test_admin_context()
        self.test_block_device_info = None,
        self.instance = utils.get_test_instance()
        self.test_network_info = utils.get_test_network_info(),
        self.node_info = bm_db_utils.new_bm_node(
                service_host='test_host',
                cpus=4,
                memory_mb=2048,
                prov_mac_address='11:11:11:11:11:11',
            )
        self.nic_info = [
                {'address': '22:22:22:22:22:22', 'datapath_id': '0x1',
                    'port_no': 1},
                {'address': '33:33:33:33:33:33', 'datapath_id': '0x2',
                    'port_no': 2},
            ]
Ejemplo n.º 24
0
 def _create_nodes(self):
     nodes = [
         utils.new_bm_node(pm_address='0', service_host="host1",
                           memory_mb=100000, cpus=100, local_gb=10000),
         utils.new_bm_node(pm_address='1', service_host="host2",
                           instance_uuid='A',
                           memory_mb=100000, cpus=100, local_gb=10000),
         utils.new_bm_node(pm_address='2', service_host="host2",
                            memory_mb=1000, cpus=1, local_gb=1000),
         utils.new_bm_node(pm_address='3', service_host="host2",
                            memory_mb=1000, cpus=2, local_gb=1000),
         utils.new_bm_node(pm_address='4', service_host="host2",
                            memory_mb=2000, cpus=1, local_gb=1000),
         utils.new_bm_node(pm_address='5', service_host="host2",
                            memory_mb=2000, cpus=2, local_gb=1000),
     ]
     self.ids = []
     for n in nodes:
         ref = db.bm_node_create(self.context, n)
         self.ids.append(ref['id'])
Ejemplo n.º 25
0
 def _create_nodes(self):
     nodes = [
         utils.new_bm_node(pm_address='0', service_host="host1",
                           memory_mb=100000, cpus=100, local_gb=10000),
         utils.new_bm_node(pm_address='1', service_host="host2",
                           instance_uuid='A',
                           memory_mb=100000, cpus=100, local_gb=10000),
         utils.new_bm_node(pm_address='2', service_host="host2",
                            memory_mb=1000, cpus=1, local_gb=1000),
         utils.new_bm_node(pm_address='3', service_host="host2",
                            memory_mb=1000, cpus=2, local_gb=1000),
         utils.new_bm_node(pm_address='4', service_host="host2",
                            memory_mb=2000, cpus=1, local_gb=1000),
         utils.new_bm_node(pm_address='5', service_host="host2",
                            memory_mb=2000, cpus=2, local_gb=1000),
     ]
     self.ids = []
     for n in nodes:
         ref = db.bm_node_create(self.context, n)
         self.ids.append(ref['id'])
Ejemplo n.º 26
0
 def test_bm_pxe_ip_associate(self):
     self._create_pxe_ip()
     node = db.bm_node_create(self.context, utils.new_bm_node())
     ip_id = db.bm_pxe_ip_associate(self.context, node['id'])
     ref = db.bm_pxe_ip_get(self.context, ip_id)
     self.assertEqual(ref['bm_node_id'], node['id'])
Ejemplo n.º 27
0
    def test_max_sum_baremetal_resources(self):
        N1 = utils.new_bm_node(service_host="host1", cpus=1,
                                      memory_mb=1000, local_gb=10)
        N2 = utils.new_bm_node(service_host="host1", cpus=1,
                                      memory_mb=1000, local_gb=20)
        N3 = utils.new_bm_node(service_host="host1", cpus=10,
                                      memory_mb=1000, local_gb=20)
        N4 = utils.new_bm_node(service_host="host1", cpus=1,
                                      memory_mb=2000, local_gb=20)
        ns = [N1, N2, N3, N4, ]
        context = test_utils.get_test_admin_context()
        self.stubs.Set(bm_driver, '_get_baremetal_nodes', lambda ctx: ns)
        drv = bm_driver.BareMetalDriver()

        dic = drv._max_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 1)
        self.assertEqual(dic.get('memory_mb'), 2000)
        self.assertEqual(dic.get('local_gb'), 20)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)
        dic = drv._sum_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 13)
        self.assertEqual(dic.get('memory_mb'), 5000)
        self.assertEqual(dic.get('local_gb'), 70)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)

        N4['instance_uuid'] = '1'
        dic = drv._max_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 10)
        self.assertEqual(dic.get('memory_mb'), 1000)
        self.assertEqual(dic.get('local_gb'), 20)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)
        dic = drv._sum_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 13)
        self.assertEqual(dic.get('memory_mb'), 5000)
        self.assertEqual(dic.get('local_gb'), 70)
        self.assertEqual(dic.get('vcpus_used'), 1)
        self.assertEqual(dic.get('memory_mb_used'), 2000)
        self.assertEqual(dic.get('local_gb_used'), 20)

        N3['instance_uuid'] = '2'
        dic = drv._max_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 1)
        self.assertEqual(dic.get('memory_mb'), 1000)
        self.assertEqual(dic.get('local_gb'), 20)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)
        dic = drv._sum_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 13)
        self.assertEqual(dic.get('memory_mb'), 5000)
        self.assertEqual(dic.get('local_gb'), 70)
        self.assertEqual(dic.get('vcpus_used'), 11)
        self.assertEqual(dic.get('memory_mb_used'), 3000)
        self.assertEqual(dic.get('local_gb_used'), 40)

        N2['instance_uuid'] = '3'
        dic = drv._max_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 1)
        self.assertEqual(dic.get('memory_mb'), 1000)
        self.assertEqual(dic.get('local_gb'), 10)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)
        dic = drv._sum_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 13)
        self.assertEqual(dic.get('memory_mb'), 5000)
        self.assertEqual(dic.get('local_gb'), 70)
        self.assertEqual(dic.get('vcpus_used'), 12)
        self.assertEqual(dic.get('memory_mb_used'), 4000)
        self.assertEqual(dic.get('local_gb_used'), 60)

        N1['instance_uuid'] = '4'
        dic = drv._max_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 0)
        self.assertEqual(dic.get('memory_mb'), 0)
        self.assertEqual(dic.get('local_gb'), 0)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)
        dic = drv._sum_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 13)
        self.assertEqual(dic.get('memory_mb'), 5000)
        self.assertEqual(dic.get('local_gb'), 70)
        self.assertEqual(dic.get('vcpus_used'), 13)
        self.assertEqual(dic.get('memory_mb_used'), 5000)
        self.assertEqual(dic.get('local_gb_used'), 70)

        N2['instance_uuid'] = None
        dic = drv._max_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 1)
        self.assertEqual(dic.get('memory_mb'), 1000)
        self.assertEqual(dic.get('local_gb'), 20)
        self.assertEqual(dic.get('vcpus_used'), 0)
        self.assertEqual(dic.get('memory_mb_used'), 0)
        self.assertEqual(dic.get('local_gb_used'), 0)
        dic = drv._sum_baremetal_resources(context)
        self.assertEqual(dic.get('vcpus'), 13)
        self.assertEqual(dic.get('memory_mb'), 5000)
        self.assertEqual(dic.get('local_gb'), 70)
        self.assertEqual(dic.get('vcpus_used'), 12)
        self.assertEqual(dic.get('memory_mb_used'), 4000)
        self.assertEqual(dic.get('local_gb_used'), 50)
Ejemplo n.º 28
0
 def test_bm_pxe_ip_associate(self):
     self._create_pxe_ip()
     node = db.bm_node_create(self.context, utils.new_bm_node())
     ip_id = db.bm_pxe_ip_associate(self.context, node['id'])
     ref = db.bm_pxe_ip_get(self.context, ip_id)
     self.assertEqual(ref['bm_node_id'], node['id'])
Ejemplo n.º 29
0
        pass

    def unplug(self, instance, vif):
        pass


FakeFirewallDriver = NoopFirewallDriver


class FakeVolumeDriver(volume_driver.VolumeDriver):
    def __init__(self):
        super(FakeVolumeDriver, self).__init__()
        self._initiator = "testtesttest"


NODE = utils.new_bm_node(cpus=2, memory_mb=4096, service_host="host1")
NICS = [
    {
        'address': '01:23:45:67:89:01',
        'datapath_id': '0x1',
        'port_no': 1,
    },
    {
        'address': '01:23:45:67:89:02',
        'datapath_id': '0x2',
        'port_no': 2,
    },
]


def class_path(class_):
Ejemplo n.º 30
0
    def plug(self, instance, vif):
        pass

    def unplug(self, instance, vif):
        pass

FakeFirewallDriver = NoopFirewallDriver


class FakeVolumeDriver(volume_driver.VolumeDriver):
    def __init__(self, virtapi):
        super(FakeVolumeDriver, self).__init__(virtapi)
        self._initiator = "testtesttest"


NODE = utils.new_bm_node(cpus=2, memory_mb=4096, service_host="host1")
NICS = [
       {'address': '01:23:45:67:89:01', 'datapath_id': '0x1', 'port_no': 1, },
       {'address': '01:23:45:67:89:02', 'datapath_id': '0x2', 'port_no': 2, },
        ]


def class_path(class_):
    return class_.__module__ + '.' + class_.__name__


COMMON_FLAGS = dict(
    baremetal_sql_connection='sqlite:///:memory:',
    baremetal_driver='nova.virt.baremetal.fake.Fake',
    power_manager='nova.virt.baremetal.fake.FakePowerManager',
    baremetal_vif_driver=class_path(FakeVifDriver),