def testCreateDirStoragePool(self):
        name = 'test_storage_pool_' + MachinesLib.random_string()
        path = '/home/test_' + MachinesLib.random_string()
        self.machine.execute('sudo mkdir -p {}'.format(path))

        self.click(self.wait_css('#card-pf-storage-pools > h2 > button',
                                 cond=clickable))
        self.wait_css('#storage-pools-listing')

        pool_name = self.create_storage_by_ui(name=name, target_path=path)
        # Get information from page
        page_res = self.wait_css(
            'tr[data-row-id="' + pool_name + '"] > td:nth-child(4)').text.split('/')
        allocation_from_page = float(page_res[0].strip())
        capacity_from_page = float(page_res[1].split(' ')[1])
        # Get information from command line
        cmd_res = self.machine.execute(
            'sudo virsh pool-info --bytes {}'.format(name))
        allocation_from_cmd = round(float(re.compile(r'Allocation:.*')
                                          .search(cmd_res)
                                          .group(0)
                                          .split(' ')[-1]) / (1024 ** 3),
                                    2)
        capacity_from_cmd = round(float(re.compile(r'Capacity:.*')
                                        .search(cmd_res)
                                        .group(0)
                                        .split(' ')[-1]) / (1024 ** 3),
                                  2)
        # Compare
        self.assertEqual(allocation_from_page, allocation_from_cmd)
        self.assertEqual(capacity_from_page, capacity_from_cmd)
    def testAddAllPhysicalDiskDevice(self):
        name = 'pdd_' + MachinesLib.random_string()
        pdd = Disc(self.machine)
        device_suffix = 'test' + MachinesLib.random_string()
        device = pdd.adddisc(device_suffix, '100M')

        # Switch from 'Virtual Machines page' to the 'Storage Pool page',
        # and click the button of storage pool creation to get the type of
        # the physical disk device
        parts = self.get_pdd_format_list()
        for part in parts:
            self.machine.execute(
                'sudo dd if=/dev/zero of={} bs=4K count=1024'.format(device))
            pdd.createparttable(device_suffix,
                                parttable='msdos' if part == 'dos' else part)
            pool_name = self.create_storage_by_ui(name=name,
                                                  storage_type='disk',
                                                  target_path='/media',
                                                  source_path=device,
                                                  parted=part)
            self.click(self.wait_css('#{}-name'.format(pool_name), cond=clickable))
            self.click(self.wait_css('#delete-{}'.format(pool_name), cond=clickable))
            self.click(self.wait_css('.modal-dialog button.pf-m-danger', cond=clickable))
            self.wait_dialog_disappear()
            self.wait_css('#{}-name'.format(pool_name), cond=invisible)

        pdd.clear()
    def testCreateNFSStoragePool(self):
        name = 'test_nfs_storage_pool_' + MachinesLib.random_string()
        path = '/home/test_nfs_' + MachinesLib.random_string()
        self.storage_pool['pool'] = name
        self.machine.execute('sudo mkdir -p {}'.format(path))

        self.click(self.wait_text('Storage Pools', cond=clickable))
        self.wait_css('#storage-pools-listing')

        pool_name = self.create_storage_by_ui(
            name=name, storage_type='netfs', target_path=path,
            host=os.environ.get('NFS'), source_path='/home/nfs', start_up=False)

        info = self.wait_css(
            'tr[data-row-id="' + pool_name + '"] > td:nth-child(4)').text.split(
            '/')
        allocation_from_page = '%.2f' % float(info[0].strip())
        capacity_from_page = '%.2f' % float(info[1].split(' ')[1])

        allocation_from_cmd = self.machine.execute('sudo virsh pool-info {} | grep Allocation'.format(name)).split(' ')
        capacity_from_cmd = self.machine.execute('sudo virsh pool-info {} | grep Capacity'.format(name)).split(' ')

        if allocation_from_cmd[-1].strip() == 'MiB':
            allocation_from_cmd = '%.2f' % (float(allocation_from_cmd[-2]) / 1024)
        else:
            allocation_from_cmd = '%.2f' % float(allocation_from_cmd[-2])
        if capacity_from_cmd[-1].strip() == 'MiB':
            capacity_from_cmd = '%.2f' % (float(capacity_from_cmd[-2]) / 1024)
        else:
            capacity_from_cmd = '%.2f' % float(capacity_from_cmd[-2])

        self.assertEqual(allocation_from_page, allocation_from_cmd)
        self.assertEqual(capacity_from_page, capacity_from_cmd)
Ejemplo n.º 4
0
    def testDeleteStoragePool(self):
        name = 'test_act_' + MachinesLib.random_string()
        path = '/home/' + name
        vol_name = 'test_vol_' + MachinesLib.random_string()
        self.machine.execute('sudo mkdir -p {}'.format(path))
        self.click(
            self.wait_css('#card-pf-storage-pools > h2 > button',
                          cond=clickable))
        self.wait_css('#storage-pools-listing')

        # Create an active storage pool,
        # then delete it without deleting volumes in it
        el_id_prefix = self.create_storage_by_ui(name=name, target_path=path)
        self.machine.execute('sudo virsh vol-create-as {} {} 10M'.format(
            name, vol_name))
        self.click(
            self.wait_css('#{}-name'.format(el_id_prefix), cond=clickable))
        self.click(
            self.wait_css('#delete-{}'.format(el_id_prefix), cond=clickable))
        self.click(
            self.wait_xpath(
                '/html/body/div[2]/div[2]/div/div/div[3]/button[2]',
                cond=clickable))
        self.wait_css('#{}-name'.format(el_id_prefix), cond=invisible)
        self.machine.execute('sudo test -f {}/{}'.format(path, vol_name))

        # Re-create the storage pool,
        # then delete it with deleting volumes in it
        el_id_prefix = self.create_storage_by_ui(name=name, target_path=path)
        self.click(
            self.wait_css('#{}-name'.format(el_id_prefix), cond=clickable))
        self.click(
            self.wait_css('#delete-{}'.format(el_id_prefix), cond=clickable))
        self.check_box(self.wait_css('#storage-pool-delete-volumes'))
        self.click(
            self.wait_xpath(
                '/html/body/div[2]/div[2]/div/div/div[3]/button[2]',
                cond=clickable))
        self.wait_dialog_disappear()
        self.wait_css('#{}-name'.format(el_id_prefix), cond=invisible)
        self.machine.execute('sudo su -c "! test -f {}/{}"'.format(
            path, vol_name))

        # Create the pool whose state is inactive, then delete it
        el_id_prefix = self.create_storage(name, path)
        self.click(
            self.wait_css('#{}-name'.format(el_id_prefix), cond=clickable))
        self.click(
            self.wait_css('#delete-{}'.format(el_id_prefix), cond=clickable))
        self.click(
            self.wait_xpath(
                '/html/body/div[2]/div[2]/div/div/div[3]/button[2]',
                cond=clickable))
        self.wait_css('#{}-name'.format(el_id_prefix), cond=invisible)
Ejemplo n.º 5
0
    def testDetachDiskVmOff(self):
        name = "staticvm"
        self.create_vm(name, state='shut off')

        self.click(self.wait_css('#vm-{}-disks'.format(name), cond=clickable))
        self.click(
            self.wait_css('#vm-{}-disks-adddisk'.format(name), cond=clickable))
        self.select_by_value(
            self.wait_css('#vm-{}-disks-adddisk-new-select-pool'.format(name)),
            'default')
        self.send_keys(
            self.wait_css('#vm-{}-disks-adddisk-new-name'.format(name)),
            'detachdisk_vm_off_' + MachinesLib.random_string())
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-dialog-add'.format(name),
                          cond=clickable))
        self.wait_css('#vm-{}-disks-vdb-device'.format(name))
        self.click(
            self.wait_css('#delete-{}-disk-vdb'.format(name), cond=clickable))
        self.click(
            self.wait_css('.modal-footer button.pf-m-danger'.format(name),
                          cond=clickable))
        self.wait_css('#vm-{}-disks-vdb-device'.format(name), cond=invisible)
        self.click(self.wait_css('#vm-{}-run'.format(name), cond=clickable))
        self.wait_css('#vm-{}-run'.format(name), cond=invisible)
        self.wait_css('#vm-{}-disks-vdb-device'.format(name), cond=invisible)

        self.assertEqual(
            self.machine.execute(
                'sudo virsh domblklist ' + name +
                ' | awk \'NR>=3{if($0!="")print}\' | wc -l').strip(), '1')
    def testCheckStateOfStoragePool(self):
        name = 'test_act_' + MachinesLib.random_string()
        path = '/home/' + name

        self.machine.execute('sudo mkdir -p {}'.format(path))
        self.click(self.wait_css('#card-pf-storage-pools > h2 > button',
                                 cond=clickable))
        self.wait_css('#storage-pools-listing')

        el_id_prefix = self.create_storage_by_ui(name=name, target_path=path)
        self.click(self.wait_css('#{}-name'.format(el_id_prefix),
                                 cond=clickable))

        self.click(self.wait_css('#deactivate-{}'.format(el_id_prefix),
                                 cond=clickable))
        self.wait_css('#{}-state'.format(el_id_prefix),
                      cond=text_in,
                      text_='inactive')
        self.assertEqual('inactive', self.machine.execute(
            'sudo virsh pool-list --all | grep %s | awk \'{print $2}\'' % name).strip())

        self.click(self.wait_css('#activate-{}'.format(el_id_prefix),
                                 cond=clickable))
        self.wait_css('#{}-state'.format(el_id_prefix),
                      cond=text_in,
                      text_='active')
        # After re-activating, the state of storage pool
        # which is got from back-end will be changed to 'running'
        self.assertEqual('active', self.machine.execute(
            'sudo virsh pool-list --all | grep %s | awk \'{print $2}\'' % name).strip())
Ejemplo n.º 7
0
    def testDetachDiskVmOn(self):
        name = "staticvm"
        self.create_vm(name, wait=True)

        self.click(self.wait_css('#vm-{}-disks'.format(name), cond=clickable))
        self.click(
            self.wait_css('#vm-{}-disks-adddisk'.format(name), cond=clickable))
        self.select_by_value(
            self.wait_css('#vm-{}-disks-adddisk-new-select-pool'.format(name)),
            'default')
        self.send_keys(
            self.wait_css('#vm-{}-disks-adddisk-new-name'.format(name)),
            'detachdisk_vm_on_' + MachinesLib.random_string())
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-dialog-add'.format(name),
                          cond=clickable))
        self.wait_css('#vm-{}-disks-vda-device'.format(name))
        self.click(
            self.wait_css('#vm-{}-disks-vda-detach'.format(name),
                          cond=clickable))
        self.wait_css('vm-{}-disks-vda-device'.format(name), cond=invisible)
        self.click(self.wait_css('#vm-{}-off'.format(name), cond=clickable))
        self.wait_css('#vm-{}-off'.format(name), cond=invisible)
        self.click(self.wait_css('#vm-{}-run'.format(name), cond=clickable))
        self.wait_css('#vm-{}-run'.format(name), cond=invisible)
        self.wait_css('#vm-{}-disks-vda-device'.format(name), cond=invisible)

        self.assertEqual(
            self.machine.execute(
                'sudo virsh domblklist ' + name +
                ' | awk \'NR>=3{if($0!="")print}\' | wc -l').strip(), '1')
Ejemplo n.º 8
0
    def testAddISCSIStoragePool(self):
        self.click(self.wait_text('Storage Pools', cond=clickable))
        self.wait_css('#storage-pools-listing')

        disc = Disc(self.machine)
        name = 'iscsi_' + MachinesLib.random_string()
        iscsi_name = disc.addtarget('test' + MachinesLib.random_string(),
                                    '100M')

        # iscsiadm needs sudo privilege, so connection must be 'system'
        self.create_storage_by_ui(name=name,
                                  storage_type='iscsi',
                                  target_path='/dev/disk/by-path',
                                  host='127.0.0.1',
                                  source_path=iscsi_name)

        disc.clear()
    def testCreateDirStoragePool(self):
        name = 'test_storage_pool_' + MachinesLib.random_string()
        path = '/home/test_' + MachinesLib.random_string()
        self.machine.execute('sudo mkdir -p {}'.format(path))

        pool_name = self.create_storage_by_ui(name=name, target_path=path)

        info = self.wait_css('tr[data-row-id="' + pool_name +
                             '"] > td:nth-child(4)').text.split('/')
        allocation_from_page = '%.2f' % float(info[0].strip())
        capacity_from_page = '%.2f' % float(info[1].split(' ')[1])

        allocation_from_cmd = self.machine.execute(
            'sudo virsh pool-info {} | grep Allocation'.format(name)).split(
                ' ')
        capacity_from_cmd = self.machine.execute(
            'sudo virsh pool-info {} | grep Capacity'.format(name)).split(' ')

        if allocation_from_cmd[-1].strip() == 'MiB':
            allocation_from_cmd = '%.2f' % (float(allocation_from_cmd[-2]) /
                                            1024)
        elif allocation_from_cmd[-1].strip() == 'TiB':
            allocation_from_page = '%.2f' % (float(allocation_from_page) /
                                             1024)
            allocation_from_cmd = '%.2f' % float(allocation_from_cmd[-2])
        else:
            allocation_from_cmd = '%.2f' % float(allocation_from_cmd[-2])

        if capacity_from_cmd[-1].strip() == 'MiB':
            capacity_from_cmd = '%.2f' % (float(capacity_from_cmd[-2]) / 1024)
        elif capacity_from_cmd[-1].strip() == 'TiB':
            capacity_from_page = '%.2f' % (float(capacity_from_page) / 1024)
            capacity_from_cmd = '%.2f' % float(capacity_from_cmd[-2])
        else:
            capacity_from_cmd = '%.2f' % float(capacity_from_cmd[-2])

        self.assertEqual(allocation_from_page, allocation_from_cmd)
        self.assertEqual(capacity_from_page, capacity_from_cmd)
Ejemplo n.º 10
0
    def testCreateVMWithISO(self):
        name = 'test_iso'
        iso_path = '/home/{}.iso'.format(name + MachinesLib.random_string())
        self.vm_stop_list.append(name)

        self.machine.execute('sudo touch {}'.format(iso_path))

        self.create_vm_by_ui(connection='session',
                             name=name,
                             source=iso_path,
                             mem=128,
                             mem_unit='M',
                             storage=50,
                             storage_unit='M')
    def testCreateNFSStoragePool(self):
        name = 'test_nfs_storage_pool_' + MachinesLib.random_string()
        path = '/home/test_nfs_' + MachinesLib.random_string()
        self.storage_pool['pool'] = name
        self.machine.execute('sudo mkdir -p {}'.format(path))

        self.click(self.wait_css('#card-pf-storage-pools > h2 > button',
                                 cond=clickable))
        self.wait_css('#storage-pools-listing')

        pool_name = self.create_storage_by_ui(name=name,
                                              storage_type='netfs',
                                              target_path=path,
                                              host=os.environ.get('NFS'),
                                              source_path='/home/nfs',
                                              start_up=False)

        page_res = self.wait_css('tr[data-row-id="' + pool_name + '"] > td:nth-child(4)').text.split('/')
        allocation_from_page = float(page_res[0].strip())
        capacity_from_page = float(page_res[1].split(' ')[1])

        cmd_res = self.machine.execute(
            'sudo virsh pool-info --bytes {}'.format(name))
        allocation_from_cmd = round(float(re.compile(r'Allocation:.*')
                                          .search(cmd_res)
                                          .group(0)
                                          .split(' ')[-1]) / (1024 ** 3),
                                    2)
        capacity_from_cmd = round(float(re.compile(r'Capacity:.*')
                                        .search(cmd_res)
                                        .group(0)
                                        .split(' ')[-1]) / (1024 ** 3),
                                  2)

        self.assertEqual(allocation_from_page, allocation_from_cmd)
        self.assertEqual(capacity_from_page, capacity_from_cmd)
Ejemplo n.º 12
0
    def testAddDiskWithVmOff(self):
        name = "staticvm"
        self.create_vm(name, state='shut off')
        pool = self.prepare_disk('test')

        self.click(self.wait_css('#vm-{}-disks'.format(name), cond=clickable))
        self.click(
            self.wait_css('#vm-{}-disks-adddisk'.format(name), cond=clickable))
        self.select_by_value(
            self.wait_css('#vm-{}-disks-adddisk-new-select-pool'.format(name)),
            pool[1])
        self.send_keys(
            self.wait_css('#vm-{}-disks-adddisk-new-name'.format(name)),
            'qcow2disk_' + MachinesLib.random_string())
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-dialog-add'.format(name),
                          cond=clickable))
        self.wait_dialog_disappear()
        self.wait_css('#vm-{}-disks-vdb-device'.format(name))

        self.click(
            self.wait_css('#vm-{}-disks-adddisk'.format(name), cond=clickable))
        self.select_by_value(
            self.wait_css('#vm-{}-disks-adddisk-new-select-pool'.format(name)),
            pool[2])
        self.send_keys(
            self.wait_css('#vm-{}-disks-adddisk-new-name'.format(name)),
            'raw2disk_' + MachinesLib.random_string())
        self.select_by_value(
            self.wait_css('#vm-{}-disks-adddisk-new-format'.format(name)),
            'raw')
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-dialog-add'.format(name),
                          cond=clickable))
        self.wait_dialog_disappear()
        self.wait_css('#vm-{}-disks-vdc-device'.format(name))

        self.click(
            self.wait_css('#vm-{}-disks-adddisk'.format(name), cond=clickable))
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-useexisting'.format(name),
                          cond=clickable))
        self.select_by_value(
            self.wait_css(
                '#vm-{}-disks-adddisk-existing-select-pool'.format(name)),
            pool[1])
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-dialog-add'.format(
                name, cond=clickable)))
        self.wait_dialog_disappear()
        self.wait_css('#vm-{}-disks-vdd-device'.format(name))

        self.click(
            self.wait_css('#vm-{}-disks-adddisk'.format(name), cond=clickable))
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-useexisting'.format(name),
                          cond=clickable))
        self.select_by_value(
            self.wait_css(
                '#vm-{}-disks-adddisk-existing-select-pool'.format(name)),
            pool[2])
        self.select_by_value(
            self.wait_css(
                '#vm-{}-disks-adddisk-existing-select-volume'.format(name)),
            pool[0][pool[2]][1])
        self.click(
            self.wait_css('#vm-{}-disks-adddisk-dialog-add'.format(
                name, cond=clickable)))
        self.wait_dialog_disappear()
        self.wait_css('#vm-{}-disks-vde-device'.format(name))

        self.click(self.wait_css('#vm-{}-run'.format(name), cond=clickable))
        self.wait_css('#vm-{}-run'.format(name), cond=invisible)

        self.assertEqual(
            self.machine.execute(
                "sudo virsh list --all | grep staticvm | awk '{print $3}' ORS=''"
            ), 'running')
        self.assertEqual(
            self.machine.execute(
                'sudo virsh domblklist ' + name +
                ' | awk \'NR>=3{if($0!="")print}\' | wc -l').strip(), '5')