def test_start(self, mock_isfile, mock_libvirt_conn, mock_configure_disk, mock_update_xml): mock_isfile.return_value = True domain = mock_libvirt_conn.return_value.defineXML.return_value node = OvercloudNode(role='controller', ip='123.123.123.123', ovs_ctrlrs=None, ovs_mgrs=None, name='dummy-controller-0', node_xml=os.path.join(TEST_DUMMY_CONFIG, 'baremetal0.xml'), disk_img='dummy.qcow2') node.start() domain.create.assert_called()
def parse_and_create_nodes(self): """ Parse snapshot node.yaml config file and create overcloud nodes :return: None """ node_file = os.path.join(self.snap_cache_dir, 'node.yaml') if not os.path.isfile(node_file): raise exc.SnapshotDeployException('Missing node definitions from ' ''.format(node_file)) node_data = utils.parse_yaml(node_file) if 'servers' not in node_data: raise exc.SnapshotDeployException('Invalid node.yaml format') for node, data in node_data['servers'].items(): logging.info('Creating node: {}'.format(node)) logging.debug('Node data is:\n{}'.format(pprint.pformat(data))) node_xml = os.path.join(self.snap_cache_dir, '{}.xml'.format(data['vNode-name'])) node_qcow = os.path.join(self.snap_cache_dir, '{}.qcow2'.format(data['vNode-name'])) self.oc_nodes.append( OvercloudNode(ip=data['address'], ovs_ctrlrs=data['ovs-controller'], ovs_mgrs=data['ovs-managers'], role=data['type'], name=node, node_xml=node_xml, disk_img=node_qcow)) logging.info('Node Created') logging.info('Starting nodes') for node in self.oc_nodes: node.start()
def test_init(self, mock_libvirt_open, mock_is_file, mock_node_create): mock_is_file.return_value = True OvercloudNode(role='controller', ip='123.123.123.123', ovs_ctrlrs=None, ovs_mgrs=None, name='dummy-controller-0', node_xml='dummynode.xml', disk_img='dummy.qcow2') mock_node_create.assert_called()
def test_update_xml_no_disk(self, mock_linux_distro): mock_linux_distro.return_value = ['Fedora'] xml_file = os.path.join(TEST_DUMMY_CONFIG, 'baremetal0.xml') with open(xml_file, 'r') as fh: xml = fh.read() new_xml = OvercloudNode._update_xml(xml=xml) self.assertIn('/home/images/baremetal0.qcow2', new_xml) self.assertIn('/usr/bin/qemu-kvm', new_xml)
def test_configure_disk(self, mock_libvirt_open, mock_is_file, mock_node_create, mock_copy): mock_is_file.return_value = True node = OvercloudNode(role='controller', ip='123.123.123.123', ovs_ctrlrs=None, ovs_mgrs=None, name='dummy-controller-0', node_xml='dummynode.xml', disk_img='dummy.qcow2') conn = mock_libvirt_open.return_value conn.storagePoolLookupByName.return_value.XMLDesc.return_value = """ <pool type='dir'> <target> <path>/var/lib/libvirt/images</path> </target> </pool> """ node._configure_disk('dummy.qcow2') mock_copy.assert_called() self.assertEqual(node.disk_img, '/var/lib/libvirt/images/dummy.qcow2')
def test_start_fail(self, mock_isfile, mock_libvirt_conn, mock_configure_disk, mock_update_xml): mock_isfile.return_value = True domain = mock_libvirt_conn.return_value.defineXML.return_value domain.create.side_effect = libvirtError('blah') node = OvercloudNode(role='controller', ip='123.123.123.123', ovs_ctrlrs=None, ovs_mgrs=None, name='dummy-controller-0', node_xml=os.path.join(TEST_DUMMY_CONFIG, 'baremetal0.xml'), disk_img='dummy.qcow2') self.assertRaises(exc.OvercloudNodeException, node.start)
def test_configure_disk_no_pool(self, mock_libvirt_open, mock_is_file, mock_node_create, mock_copy): mock_is_file.return_value = True node = OvercloudNode(role='controller', ip='123.123.123.123', ovs_ctrlrs=None, ovs_mgrs=None, name='dummy-controller-0', node_xml='dummynode.xml', disk_img='dummy.qcow2') conn = mock_libvirt_open.return_value conn.storagePoolLookupByName.return_value = None self.assertRaises(exc.OvercloudNodeException, node._configure_disk, 'dummy.qcow2')