Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    def test_external_snapshot_revert_with_children_revert_present(
            self, mock_revert_snapshot_recreate_disks,
            mock_revert_snapshot, mock_get_snapshot, mock_has_snapshot,
            mock_destroy, mock_update_disks_from_snapshot):
        revert_postfix = '-revert3'

        def get_snapshot(node, snapname):
            if snapname.endswith(revert_postfix):
                return mock.Mock(get_type='external', children_num=0)
            else:
                return mock.Mock(get_type='external', children_num=1)

        mock_has_snapshot.return_value = True
        mock_get_snapshot.side_effect = get_snapshot
        environment = Environment.create('test_env_extsnap')
        node = Node.node_create(name='test_node', environment=environment)
        environment.define()
        snapshot_name = factories.fuzzy_string('snap_')
        node.revert(name=snapshot_name, destroy=False)

        revert_snapshot_name = '{0}{1}'.format(snapshot_name, revert_postfix)
        mock_update_disks_from_snapshot.assert_called_with(
            revert_snapshot_name)
        mock_revert_snapshot_recreate_disks.assert_called_with(
            node, revert_snapshot_name)
        mock_revert_snapshot.assert_called_with(node=node,
                                                name=revert_snapshot_name)
Esempio n. 4
0
    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)
Esempio n. 5
0
    def test_snapshot_with_existing_name_force_delete(self, mock_has_snapshot,
                                                      mock_delete_snapshot,
                                                      mock_create_snapshot):
        mock_has_snapshot.return_value = True

        environment = Environment.create('test_env_extsnap')
        node = Node.node_create(name='test_node', environment=environment)
        environment.define()

        snap_name = factories.fuzzy_string('snap_')
        snap_description = factories.fuzzy_string('description_')

        node.snapshot(
            name=snap_name,
            force=True,
            description=snap_description,
            disk_only=True)

        self.assertEqual(mock_delete_snapshot.called, True)
        mock_delete_snapshot.assert_called_with(node=node, name=snap_name)
        mock_create_snapshot.assert_called_with(
            node=node,
            name=snap_name,
            description=snap_description,
            disk_only=True,
            external=False)
Esempio n. 6
0
    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)
Esempio n. 7
0
 def test_node_creation(self):
     environment = Environment.create('test_env3')
     internal = Network.network_create(
         environment=environment, name='internal', pool=None)
     node = Node.node_create(name='test_node', environment=environment)
     Interface.interface_create(node=node, network=internal)
     environment.define()
Esempio n. 8
0
 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()
Esempio n. 9
0
 def test_node_creation(self):
     environment = Environment.create('test_env3')
     internal = Network.network_create(
         environment=environment, name='internal', pool=None)
     node = Node.node_create(
         name='test_node', environment=environment)
     Interface.interface_create(node=node, network=internal)
     environment.define()
Esempio n. 10
0
 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()
Esempio n. 11
0
 def test_network_model(self):
     environment = Environment.create('test_env')
     node = Node.node_create('test_node', environment)
     network = Network.network_create(
         environment=environment, name='internal', ip_network='10.1.0.0/24')
     interface1 = Interface.interface_create(network=network, node=node)
     self.assertEquals('virtio', interface1.model)
     interface2 = Interface.interface_create(
         network=network, node=node, model='e1000')
     self.assertEquals('e1000', interface2.model)
Esempio n. 12
0
 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()
Esempio n. 13
0
 def test_network_model(self):
     environment = Environment.create('test_env')
     node = Node.node_create('test_node', environment)
     network = Network.network_create(
         environment=environment, name='internal', ip_network='10.1.0.0/24')
     interface1 = Interface.interface_create(network=network, node=node)
     self.assertEquals('virtio', interface1.model)
     interface2 = Interface.interface_create(
         network=network, node=node, model='e1000')
     self.assertEquals('e1000', interface2.model)
Esempio n. 14
0
    def test_snapshot_with_existing_name(self, mock_has_snapshot,
                                         mock_node_create_snapshot):
        mock_has_snapshot.return_value = True

        environment = Environment.create('test_env_extsnap')
        node = Node.node_create(name='test_node', environment=environment)
        environment.define()

        node.snapshot(name='test_name')
        self.assertEqual(mock_node_create_snapshot.called, False)
Esempio n. 15
0
 def test_network_iterator(self):
     environment = Environment.create('test_env')
     node = Node.node_create('test_node', environment)
     network = Network.network_create(
         environment=environment, name='internal', ip_network='10.1.0.0/24')
     interface = Interface.interface_create(network=network, node=node)
     Address.objects.create(str('10.1.0.1'), interface=interface)
     network.next_ip()
     Address.objects.create(str('10.1.0.3'), interface=interface)
     ip = network.next_ip()
     self.assertEquals('10.1.0.4', str(ip))
Esempio n. 16
0
 def test_network_iterator(self):
     environment = Environment.create('test_env')
     node = Node.node_create('test_node', environment)
     network = Network.network_create(environment=environment,
                                      name='internal',
                                      ip_network='10.1.0.0/24')
     interface = Interface.interface_create(network=network, node=node)
     Address.objects.create(str('10.1.0.1'), interface=interface)
     network.next_ip()
     Address.objects.create(str('10.1.0.3'), interface=interface)
     ip = network.next_ip()
     self.assertEquals('10.1.0.4', str(ip))
Esempio n. 17
0
    def test_external_snapshot_incorrect_libvirt_version(
            self, mock_has_snapshot, mock_libvirt_version,
            mock_create_snapshot):
        mock_has_snapshot.return_value = False
        mock_libvirt_version.return_value = 1002009

        environment = Environment.create('test_env_extsnap')
        node = Node.node_create(name='test_node', environment=environment)
        environment.define()

        node.snapshot(name='test_name', external=True)

        self.assertEqual(mock_create_snapshot.called, False)
Esempio n. 18
0
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')
Esempio n. 19
0
    def test_external_snapshot_with_children_erase(
            self, mock_has_snapshot, mock_get_snapshot, mock_delete_snapshot):
        mock_has_snapshot.return_value = True
        mock_get_snapshot.return_value = mock.Mock(
            get_type='external', children_num=1)

        environment = Environment.create('test_env_extsnap')
        node = Node.node_create(name='test_node', environment=environment)
        environment.define()

        snap_name = factories.fuzzy_string('snap_')
        node.erase_snapshot(snap_name)

        self.assertEqual(mock_delete_snapshot.called, False)
        mock_get_snapshot.assert_called_with(node, snap_name)
Esempio n. 20
0
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')
Esempio n. 21
0
    def test_external_snapshot_revert_no_children(
            self, mock_revert_snapshot_recreate_disks,
            mock_revert_snapshot, mock_get_snapshot, mock_has_snapshot,
            mock_destroy, mock_update_disks_from_snapshot):
        mock_has_snapshot.return_value = True
        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)
        environment.define()
        snapshot_name = factories.fuzzy_string('snap_')
        node.revert(name=snapshot_name, destroy=False)

        mock_update_disks_from_snapshot.assert_called_with(snapshot_name)
        mock_revert_snapshot_recreate_disks.assert_called_with(
            node, snapshot_name)
        mock_revert_snapshot.assert_called_with(node=node, name=snapshot_name)
Esempio n. 22
0
 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()
Esempio n. 23
0
 def test_node_creationw(self):
     environment = Environment.create('test_env55')
     node = Node.node_create(
         name='test_node4',
         environment=environment)
     node.define()
Esempio n. 24
0
 def test_node_creationw(self):
     environment = Environment.create('test_env55')
     node = Node.node_create(
         name='test_node4',
         environment=environment)
     node.define()