def test_create_volume(self): environment = Environment.create('test_env3') volume = Volume.volume_get_predefined( '/var/lib/libvirt/images/disk-135824657433.qcow2') v3 = Volume.volume_create_child( 'test_vp89', backing_store=volume, environment=environment) v3.define()
def test_create_node3(self): environment = Environment.create('test_env3') internal = Network.network_create(environment=environment, name='internal', pool=None) external = Network.network_create(environment=environment, name='external', pool=None) private = Network.network_create(environment=environment, name='private', pool=None) node = Node.node_create(name='test_node', environment=environment) Interface.interface_create(node=node, network=internal) Interface.interface_create(node=node, network=external) Interface.interface_create(node=node, network=private) volume = Volume.volume_get_predefined( '/var/lib/libvirt/images/disk-135824657433.qcow2') v3 = Volume.volume_create_child('test_vp892', backing_store=volume, environment=environment) v4 = Volume.volume_create_child('test_vp891', backing_store=volume, environment=environment) DiskDevice.node_attach_volume(node=node, volume=v3) DiskDevice.node_attach_volume(node, v4) environment.define()
def volume_get_predefined(self, uuid): """ :rtype : Volume """ try: return Volume.objects.get(uuid=uuid) except Volume.DoesNotExist: volume = Volume(uuid=uuid) volume.fill_from_exist() volume.save() return volume
def one(): environment = Environment.create('cdrom') internal_pool = Network.create_network_pool( networks=[IPNetwork('10.108.0.0/16')], prefix=24) private_pool = Network.create_network_pool( networks=[IPNetwork('10.108.0.0/16')], prefix=24) external_pool = Network.create_network_pool( networks=[IPNetwork('172.18.95.0/24')], prefix=27) internal = Network.network_create(environment=environment, name='internal', pool=internal_pool) external = Network.network_create(environment=environment, name='external', pool=external_pool, forward='nat') private = Network.network_create(environment=environment, name='private', pool=private_pool) for i in range(1, 2): node = Node.node_create(name='test_node' + str(i), environment=environment) Interface.interface_create(node=node, network=internal) Interface.interface_create(node=node, network=external) Interface.interface_create(node=node, network=private) volume = Volume.volume_get_predefined( '/var/lib/libvirt/images/centos63-cobbler-base.qcow2') v3 = Volume.volume_create_child('test_vp895' + str(i), backing_store=volume, environment=environment) v4 = Volume.volume_create_child('test_vp896' + str(i), backing_store=volume, environment=environment) DiskDevice.node_attach_volume(node=node, volume=v3) DiskDevice.node_attach_volume(node, v4) DiskDevice.node_attach_volume( node, Volume.volume_get_predefined( '/var/lib/libvirt/images/fuel-centos-6.3-x86_64.iso'), device='cdrom', bus='sata') environment.define() environment.start() remotes = [] for node in environment.get_nodes(): node. await ('internal') node.remote('internal', 'root', 'r00tme').check_stderr('ls -la', verbose=True) remotes.append(node.remote('internal', 'root', 'r00tme')) SSHClient.execute_together(remotes, 'ls -la')
def one(): environment = Environment.create('cdrom') internal_pool = Network.create_network_pool( networks=[IPNetwork('10.108.0.0/16')], prefix=24 ) private_pool = Network.create_network_pool( networks=[IPNetwork('10.108.0.0/16')], prefix=24 ) external_pool = Network.create_network_pool( networks=[IPNetwork('172.18.95.0/24')], prefix=27 ) internal = Network.network_create( environment=environment, name='internal', pool=internal_pool) external = Network.network_create( environment=environment, name='external', pool=external_pool, forward='nat') private = Network.network_create( environment=environment, name='private', pool=private_pool) for i in range(1, 2): node = Node.node_create( name='test_node' + str(i), environment=environment) Interface.interface_create(node=node, network=internal) Interface.interface_create(node=node, network=external) Interface.interface_create(node=node, network=private) volume = Volume.volume_get_predefined( '/var/lib/libvirt/images/centos63-cobbler-base.qcow2') v3 = Volume.volume_create_child( 'test_vp895' + str(i), backing_store=volume, environment=environment) v4 = Volume.volume_create_child( 'test_vp896' + str(i), backing_store=volume, environment=environment) DiskDevice.node_attach_volume(node=node, volume=v3) DiskDevice.node_attach_volume(node, v4) DiskDevice.node_attach_volume( node, Volume.volume_get_predefined( '/var/lib/libvirt/images/fuel-centos-6.3-x86_64.iso'), device='cdrom', bus='sata') environment.define() environment.start() remotes = [] for node in environment.get_nodes(): node.await('internal') node.remote('internal', 'root', 'r00tme').check_stderr( 'ls -la', verbose=True) remotes.append(node.remote('internal', 'root', 'r00tme')) SSHClient.execute_together(remotes, 'ls -la')
def test_external_snapshot_volume_creation(self, mock_volume_define): mock_volume_define.return_value = None environment = Environment.create('test_env_extsnap') node = Node.node_create(name='test_node', environment=environment) vol_volume_name = factories.fuzzy_string() vol = Volume.volume_create(vol_volume_name, capacity=1000000000, format='qcow2', environment=environment) DiskDevice.node_attach_volume(node=node, volume=vol) environment.define() snapshot_name = factories.fuzzy_string('snap_') snapshot_volume_name = '{0}.{1}'.format(vol_volume_name, snapshot_name) node.snapshot_create_volume(snapshot_name) vol1 = environment.get_volume(name=snapshot_volume_name) self.assertEqual(len(node.disk_devices), 1) self.assertEqual(vol1.name, snapshot_volume_name) self.assertEqual(vol1.format, 'qcow2') self.assertEqual(vol1.environment, environment) self.assertEqual(vol1.backing_store, vol) self.assertEqual(vol1, node.disk_devices[0].volume) mock_volume_define.assert_called_with(vol1)
def test_update_disks_from_snapshot_with_children( self, mock_has_snapshot, mock_volume_define, mock_libvirt_version, mock_get_snapshot, mock_create_snapshot): mock_has_snapshot.return_value = False mock_libvirt_version.return_value = 1002012 volume_path_template = '/var/lib/libvirt/images/{0}' environment = Environment.create('test_env_extsnap') node = Node.node_create(name='test_node', environment=environment) vol_volume_name = factories.fuzzy_string() vol = Volume.volume_create(vol_volume_name, capacity=1000000000, format='qcow2', environment=environment) vol.uuid = volume_path_template.format(vol_volume_name) DiskDevice.node_attach_volume(node=node, volume=vol) environment.define() snap_name = factories.fuzzy_string('snap_') snap_description = factories.fuzzy_string('description_') snapshot_volume_name = '{0}.{1}'.format(vol_volume_name, snap_name) mock_get_snapshot.return_value = mock.Mock( get_type='external', children_num=1, disks={'sda': volume_path_template.format(snap_name)}) node.snapshot(name=snap_name, description=snap_description, external=True) vol1 = environment.get_volume(name=snapshot_volume_name) vol1.uuid = volume_path_template.format(snap_name) vol1.save() node._update_disks_from_snapshot(snap_name) self.assertEqual(node.disk_devices[0].volume, vol)
def test_external_snapshot_erase( self, mock_has_snapshot, mock_volume_define, mock_libvirt_version, mock_delete_snapshot, mock_get_snapshot, mock_create_snapshot): mock_has_snapshot.return_value = False mock_libvirt_version.return_value = 1002012 mock_get_snapshot.return_value = mock.Mock(get_type='external', children_num=0) environment = Environment.create('test_env_extsnap') node = Node.node_create(name='test_node', environment=environment) vol_volume_name = factories.fuzzy_string() vol = Volume.volume_create(vol_volume_name, capacity=1000000000, format='qcow2', environment=environment) DiskDevice.node_attach_volume(node=node, volume=vol) environment.define() snap_name = factories.fuzzy_string('snap_') snap_description = factories.fuzzy_string('description_') node.snapshot(name=snap_name, description=snap_description, external=True) mock_has_snapshot.return_value = True node.erase_snapshot(snap_name) mock_delete_snapshot.assert_called_with(node=node, name=snap_name) self.assertEqual(node.disk_devices[0].volume, vol)
def test_external_snapshot( self, mock_has_snapshot, mock_create_volume, mock_libvirt_version, mock_create_snapshot): mock_has_snapshot.return_value = False mock_libvirt_version.return_value = 1002012 environment = Environment.create('test_env_extsnap') node = Node.node_create(name='test_node', environment=environment) vol_volume_name = factories.fuzzy_string() vol = Volume.volume_create(vol_volume_name, capacity=1000000000, format='qcow2', environment=environment) DiskDevice.node_attach_volume(node=node, volume=vol) environment.define() snap_name = factories.fuzzy_string('snap_') snap_description = factories.fuzzy_string('description_') node.snapshot(name=snap_name, description=snap_description, external=True) mock_create_volume.assert_called_with(snap_name) mock_create_snapshot.assert_called_with( node=node, name=snap_name, description=snap_description, disk_only=False, external=True)
def add_nessus_node(self): node = Node.node_create(name='slave-nessus', environment=self.devops_env, boot=['hd']) node.attach_to_networks() volume = Volume.volume_get_predefined(NESSUS_IMAGE_PATH) DiskDevice.node_attach_volume(node=node, volume=volume) node.define() node.start()
def add_nessus_node(self): node = Node.node_create( name='slave-nessus', environment=self.devops_env, boot=['hd']) node.attach_to_networks() volume = Volume.volume_get_predefined(NESSUS_IMAGE_PATH) DiskDevice.node_attach_volume(node=node, volume=volume) node.define() node.start()
def test_volumes_for_pptesting(self): images_for_upload = { 'ubuntu-12.04.3-desktop-amd64.iso': '%s' % ( '/tmp/ubuntu-12.04.3-desktop-amd64.iso'), 'centos6.4-base.qcow2': '/tmp/centos6.4-base.qcow2', } for name, vol in images_for_upload.items(): v = Volume.volume_create(name, get_file_size(vol)) if not self.driver.volume_exists(v): self.driver.volume_define(v) self.driver.volume_upload(v, vol)
def test_create_node3(self): environment = Environment.create('test_env3') internal = Network.network_create( environment=environment, name='internal', pool=None) external = Network.network_create( environment=environment, name='external', pool=None) private = Network.network_create( environment=environment, name='private', pool=None) node = Node.node_create(name='test_node', environment=environment) Interface.interface_create(node=node, network=internal) Interface.interface_create(node=node, network=external) Interface.interface_create(node=node, network=private) volume = Volume.volume_get_predefined( '/var/lib/libvirt/images/disk-135824657433.qcow2') v3 = Volume.volume_create_child( 'test_vp892', backing_store=volume, environment=environment) v4 = Volume.volume_create_child( 'test_vp891', backing_store=volume, environment=environment) DiskDevice.node_attach_volume(node=node, volume=v3) DiskDevice.node_attach_volume(node, v4) environment.define()
def test_volumes_for_pptesting(self): images_for_upload = { 'ubuntu-12.04.3-desktop-amd64.iso': '%s' % ('/tmp/ubuntu-12.04.3-desktop-amd64.iso'), 'centos6.4-base.qcow2': '/tmp/centos6.4-base.qcow2', } for name, vol in images_for_upload.iteritems(): v = Volume.volume_create(name, _get_file_size(vol)) if not self.driver.volume_exists(v): self.driver.volume_define(v) self.driver.volume_upload(v, vol)
def volume_get_predefined(self, uuid): """ :rtype : Volume """ try: volume = Volume.objects.get(uuid=uuid) except Volume.DoesNotExist: volume = Volume(uuid=uuid) volume.fill_from_exist() volume.save() return volume