예제 #1
0
 def test_delete_path_good(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'rmdir', CONF.ovz_ve_private_dir,
         run_as_root=True).AndReturn(('', ''))
     self.mox.ReplayAll()
     self.assertTrue(ovz_utils.delete_path(CONF.ovz_ve_private_dir))
예제 #2
0
    def _partition_disk(self):
        """
        Openvz requires that we pass in not only the root device but if the
        user is to access partitions on that disk we need also to pass in
        the major/minor numbers for each partition.  Given that requirement
        we're making the assumption for now that volumes are going to be
        presented as one partition.  This will partition the root device so
        we can later get the information on both the major and minor numbers.

        If the disk contains a valid partition table then we just return

        :return:
        """
        # We need potentially need to give the device time to settle
        self._let_disk_settle()

        dev = self._find_device()
        part_table = self._list_partition_table()
        LOG.debug(_('Partition table for %(dev)s: %(part_table)s') % locals())

        # If the volume is partitioned we're assuming this is a reconnect of
        # a volume and we won't partition anything.
        if not part_table:
            commands = ['o,w', 'n,p,1,,,t,1,83,w']

            for command in commands:
                command = command.replace(',', '\n')
                ovz_utils.execute(
                    'fdisk', dev, process_input=command, run_as_root=True)
                time.sleep(3)
예제 #3
0
 def test_get_cpuunits_capability(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'vzcpucheck', run_as_root=True).AndReturn('')
     self.mox.ReplayAll()
     self.assertRaises(
         exception.InvalidCPUInfo, ovz_utils.get_cpuunits_capability)
예제 #4
0
 def quota_init(self):
     """
     Initialize quotas for instance
     """
     LOG.debug(_('Initializing quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'quotainit', self.instance['id'])
     LOG.debug(_('Initialized quotas for %s') % self.instance['id'])
예제 #5
0
 def test_set_permissions(self):
     perms = 755
     filename = '/tmp/testfile'
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute('chmod', perms, filename, run_as_root=True)
     self.mox.ReplayAll()
     ovz_utils.set_permissions(filename, perms)
예제 #6
0
 def quota_on(self):
     """
     Turn on quotas for instance
     """
     LOG.debug(_('Turning on quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'quotaon', self.instance['id'],
                       run_as_root=True)
     LOG.debug(_('Turned on quotas for %s') % self.instance['id'])
예제 #7
0
 def test_mkfs_uuid(self):
     fs_uuid = uuid.uuid4()
     path = '/dev/sdgg'
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'mkfs', '-F', '-t', 'ext3', '-U', fs_uuid, path, run_as_root=True)
     self.mox.ReplayAll()
     ovz_utils.mkfs(path, 'ext3', fs_uuid)
예제 #8
0
 def quotadump(self):
     """
     Dump the quotas for containers
     """
     LOG.debug(_('Dumping quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzdqdump', self.instance['id'], '-U', '-G',
                       '-T', '>', self.qdumpfile, run_as_root=True)
     LOG.debug(_('Dumped quotas for %s') % self.instance['id'])
예제 #9
0
 def test_execute_process_execution_error_no_raise_on_error(self):
     self.mox.StubOutWithMock(ovz_utils.utils, 'execute')
     ovz_utils.utils.execute(
         'cat', '/proc/cpuinfo', run_as_root=False).AndRaise(
             processutils.ProcessExecutionError)
     self.mox.ReplayAll()
     ovz_utils.execute(
         'cat', '/proc/cpuinfo', run_as_root=False, raise_on_error=False)
예제 #10
0
 def quotaenable(self):
     """
     enable quotas for a given container
     """
     LOG.debug(_('Enabling quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzquota', 'reload2',
                       self.instance['id'], run_as_root=True)
     LOG.debug(_('Enabled quotas for %s') % self.instance['id'])
예제 #11
0
 def test_delete_path_bad(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'rmdir', CONF.ovz_ve_private_dir,
         run_as_root=True).AndRaise(exception.InstanceUnacceptable(
             fakes.ERRORMSG))
     self.mox.ReplayAll()
     self.assertFalse(ovz_utils.delete_path(CONF.ovz_ve_private_dir))
예제 #12
0
 def quotaload(self):
     """
     Load quotas from quota file
     """
     LOG.debug(_('Loading quotas for %s') % self.instance['id'])
     ovz_utils.execute('vzdqload', self.instance['id'], '-U', '-G', '-T',
                       '<', self.qdumpfile, run_as_root=True)
     LOG.debug(_('Loaded quotas for %s') % self.instance['id'])
예제 #13
0
 def test_set_perms_success(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'chmod', 755, fakes.TEMPFILE, run_as_root=True).AndReturn(
             ('', fakes.ERRORMSG))
     self.mox.ReplayAll()
     fh = ovzfile.OVZFile(fakes.TEMPFILE, 755)
     fh.set_permissions(755)
예제 #14
0
 def resume(self):
     """
     Resume a container from an undumped migration
     """
     LOG.debug(_('Resuming instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'restore', self.instance['id'],
                       '--resume', run_as_root=True)
     LOG.debug(_('Resumed instance %s') % self.instance['id'])
예제 #15
0
 def kill(self):
     """
     This is used to stop a container once it's suspended without having to
     resume it to properly destroy it
     """
     LOG.debug(_('Killing instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'chkpnt', self.instance['id'],
                       '--kill', run_as_root=True)
     LOG.debug(_('Killed instance %s') % self.instance['id'])
예제 #16
0
 def test_get_fs_uuid_failure(self):
     dev = '/dev/sdgg'
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'blkid', '-o', 'value', '-s', 'UUID', dev,
         raise_on_error=False, run_as_root=True).AndReturn('\n')
     self.mox.ReplayAll()
     fs_uuid = ovz_utils.get_fs_uuid(dev)
     self.assertFalse(fs_uuid)
예제 #17
0
 def test_get_fs_uuid_success(self):
     dev = '/dev/sdgg'
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'blkid', '-o', 'value', '-s', 'UUID', dev,
         raise_on_error=False, run_as_root=True).AndReturn(fakes.BLKID)
     self.mox.ReplayAll()
     fs_uuid = ovz_utils.get_fs_uuid(dev)
     self.assertEqual(fs_uuid, fakes.BLKID.strip())
예제 #18
0
 def test_set_perms_failure(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'chmod', 755, fakes.TEMPFILE, run_as_root=True).AndRaise(
             exception.InstanceUnacceptable(fakes.ERRORMSG))
     self.mox.ReplayAll()
     fh = ovzfile.OVZFile(fakes.TEMPFILE, 755)
     self.assertRaises(
         exception.InstanceUnacceptable, fh.set_permissions, 755)
예제 #19
0
 def test_mkfs_label(self):
     path = '/dev/sdgg'
     fs_label = 'STORAGE'
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'mkfs', '-F', '-t', 'ext3', '-U', mox.IgnoreArg(), '-L', fs_label,
         path, run_as_root=True)
     self.mox.ReplayAll()
     ovz_utils.mkfs(path, 'ext3', None, fs_label)
예제 #20
0
 def test_touch_file_success(self):
     fh = ovzfile.OVZFile(fakes.TEMPFILE, 755)
     self.mox.StubOutWithMock(fh, 'make_path')
     fh.make_path()
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'touch', fakes.TEMPFILE, run_as_root=True).AndReturn(
             ('', fakes.ERRORMSG))
     self.mox.ReplayAll()
     fh.touch()
예제 #21
0
 def _rsync(self, src_path, dest_path):
     """
     Copy a path from one place to another using rsync
     """
     dest = "%s@%s:%s" % (self.user, self.dest_host, os.path.abspath(dest_path))
     counter = 1
     while counter <= CONF.ovz_rsync_iterations:
         LOG.debug(_("RSyncing %(src_path)s, attempt: %(counter)s") % locals())
         ovz_utils.execute("rsync", "-qavz", src_path, dest, run_as_root=True)
         counter += 1
예제 #22
0
 def test_touch_file_failure(self):
     fh = ovzfile.OVZFile(fakes.TEMPFILE, 755)
     self.mox.StubOutWithMock(fh, 'make_path')
     fh.make_path()
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'touch', fakes.TEMPFILE, run_as_root=True).AndRaise(
             exception.InstanceUnacceptable(fakes.ERRORMSG))
     self.mox.ReplayAll()
     self.assertRaises(exception.InstanceUnacceptable, fh.touch)
예제 #23
0
 def test_make_path_and_dir_success(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'mkdir', '-p', mox.IgnoreArg(), run_as_root=True).AndReturn(
             ('', fakes.ERRORMSG))
     self.mox.StubOutWithMock(openvz_conn.os.path, 'exists')
     openvz_conn.os.path.exists(mox.IgnoreArg()).AndReturn(False)
     self.mox.ReplayAll()
     fh = ovzfile.OVZFile(fakes.TEMPFILE, 755)
     fh.make_path()
예제 #24
0
 def undump(self):
     """
     Restore a VZ from a dump file
     """
     LOG.debug(_('Undumping instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'restore', self.instance['id'], '--undump',
                       '--dumpfile', self.dumpfile, '--skip_arpdetect',
                       run_as_root=True)
     LOG.debug(_('Undumped instance %(instance_id)s from %(dumpfile)s') %
               {'instance_id': self.instance['id'],
                'dumpfile': self.dumpfile})
예제 #25
0
    def _let_disk_settle(self):
        """
        Check to see if the device_name is available in /dev/disk/by-path.  If
        it isn't then we'll wait a bit and retry.  Disks don't just instantly
        show up in /dev so this gives a little bit of wait time for things
        to show up.

        :return:
        """
        ovz_utils.execute(
            'ls', self.device_name(), run_as_root=True,
            attempts=CONF.ovz_volume_settle_num_tries, delay_on_retry=True)
예제 #26
0
    def _detach_raw_device(self, major, minor):
        """
        Remove perms from the container for a device based on major and minor
        numbers.

        :param major:
        :param minor:
        :return:
        """
        ovz_utils.execute(
            'vzctl', 'set', self.instance_id, '--devices',
            'b:%s:%s:none' % (major, minor), run_as_root=True)
예제 #27
0
 def test_get_memory_mb_used_instance(self):
     self.mox.StubOutWithMock(ovz_utils, 'execute')
     ovz_utils.execute(
         'vzlist', '-H', '-o', 'ctid,privvmpages.l',
         str(fakes.INSTANCE['id']),
         raise_on_error=False, run_as_root=True).AndReturn(
             fakes.PRIVVMPAGES_2048)
     self.mox.ReplayAll()
     memory_used = ((int(
         fakes.PRIVVMPAGES_2048.strip().split()[1]) * 4096) / 1024 ** 2)
     result = ovz_utils.get_memory_mb_used(fakes.INSTANCE['id'])
     self.assertEqual(memory_used, result)
예제 #28
0
 def dump(self):
     """
     Create a vz dump file from a container.  This is the file that we
     transfer to do a full migration
     """
     LOG.debug(_('Dumping instance %s') % self.instance['id'])
     ovz_utils.execute('vzctl', 'chkpnt', self.instance['id'],
                       '--dump', '--dumpfile', self.dumpfile,
                       run_as_root=True)
     LOG.debug(_('Dumped instance %(instance_id)s to %(dumpfile)s') %
               {'instance_id': self.instance['id'],
                'dumpfile': self.dumpfile})
예제 #29
0
    def _check_device_exists(self, device_path):
        """Check that the device path exists.

        Verify that the device path has actually been created and can report
        it's size, only then can it be available for formatting, retry
        num_tries to account for the time lag.
        """
        try:
            ovz_utils.execute('blockdev', '--getsize64', device_path,
                              attempts=CONF.ovz_system_num_tries,
                              run_as_root=True)
        except processutils.ProcessExecutionError:
            raise exception.InvalidDevicePath(path=device_path)
예제 #30
0
    def _set_nameserver(self, instance_id, dns):
        """
        Get the nameserver for the assigned network and set it using
        OpenVz's tools.

        Run the command:

        vzctl set <ctid> --save --nameserver <nameserver>

        If this fails to run an exception is raised as this will indicate
        the container's inability to do name resolution.
        """
        ovz_utils.execute('vzctl', 'set', instance_id, '--save',
                          '--nameserver', dns, run_as_root=True)