Example #1
0
 def __init__(self, flags=None, default_nfs_version=None):
   if flags:
     disk_spec = disk.BaseDiskSpec(_COMPONENT, flags)
   else:
     disk_spec = disk.BaseDiskSpec(_COMPONENT)
   super(_NfsDisk, self).__init__(disk_spec, 'host1:/volume1',
                                  default_nfs_version)
Example #2
0
 def __init__(self, default_smb_version=None):
   if FLAGS:
     disk_spec = disk.BaseDiskSpec(_COMPONENT, FLAGS)
   else:
     disk_spec = disk.BaseDiskSpec(_COMPONENT)
   super(_SmbDisk, self).__init__(
       disk_spec, 'host1', {'user': '******', 'pw': 'password'},
       default_smb_version)
Example #3
0
    def testScratchDisks(self):
        """Test for creating and deleting scratch disks.

    This test creates two scratch disks on a vm and deletes them, ensuring
    that the proper calls to create, format, mount, and delete are made.
    """

        vm = self._CreateVm()

        disk_spec = disk.BaseDiskSpec(_COMPONENT, mount_point='/mountpoint0')
        vm.CreateScratchDisk(disk_spec)

        assert len(vm.scratch_disks) == 1, 'Disk not added to scratch disks.'

        scratch_disk = vm.scratch_disks[0]

        scratch_disk.Create.assert_called_once_with()
        vm.FormatDisk.assert_called_once_with(scratch_disk.GetDevicePath(),
                                              None)
        vm.MountDisk.assert_called_once_with(scratch_disk.GetDevicePath(),
                                             '/mountpoint0', None,
                                             scratch_disk.mount_options,
                                             scratch_disk.fstab_options)

        disk_spec = disk.BaseDiskSpec(_COMPONENT, mount_point='/mountpoint1')
        vm.CreateScratchDisk(disk_spec)

        assert len(vm.scratch_disks) == 2, 'Disk not added to scratch disks.'

        # Check that these execute without exceptions. The return value
        # is a MagicMock, not a string, so we can't compare to expected results.
        vm.GetScratchDir()
        vm.GetScratchDir(0)
        vm.GetScratchDir(1)
        with self.assertRaises(errors.Error):
            vm.GetScratchDir(2)

        scratch_disk = vm.scratch_disks[1]

        scratch_disk.Create.assert_called_once_with()
        vm.FormatDisk.assert_called_with(scratch_disk.GetDevicePath(), None)
        vm.MountDisk.assert_called_with(scratch_disk.GetDevicePath(),
                                        '/mountpoint1', None,
                                        scratch_disk.mount_options,
                                        scratch_disk.fstab_options)

        vm.DeleteScratchDisks()

        vm.scratch_disks[0].Delete.assert_called_once_with()
        vm.scratch_disks[1].Delete.assert_called_once_with()
Example #4
0
def Prepare(benchmark_spec):
    """Install Cassandra and Java on target vms.

  Args:
    benchmark_spec: The benchmark specification. Contains all data that is
        required to run the benchmark.
  """
    vm_dict = benchmark_spec.vm_dict
    logging.info('VM dictionary %s', vm_dict)

    if vm_dict['default']:
        logging.info('No config file is provided, use default settings: '
                     '1 loader node, 3 data nodes')
        vm_dict[LOADER_NODE] = [vm_dict['default'][-1]]
        vm_dict[DATA_NODE] = vm_dict['default'][:3]
        disk_spec = disk.BaseDiskSpec(
            500, bs.DISK_TYPE[benchmark_spec.cloud][bs.STANDARD],
            '/cassandra_data')
        for vm in vm_dict[DATA_NODE]:
            vm.CreateScratchDisk(disk_spec)

    logging.info('Authorizing loader[0] permission to access all other vms.')
    vm_dict[LOADER_NODE][0].AuthenticateVm()

    logging.info('Preparing data files and Java on all vms.')
    vm_util.RunThreaded(PrepareVm, benchmark_spec.vms)
Example #5
0
    def doAzureDiskTest(self, storage_type, disk_type, machine_type,
                        goal_media, goal_replication, goal_legacy_disk_type):
        with mock.patch(azure_disk.__name__ + '.FLAGS') as disk_flags:
            disk_flags.azure_storage_type = storage_type
            disk_spec = disk.BaseDiskSpec(_COMPONENT,
                                          disk_size=2,
                                          disk_type=disk_type)

            context.SetThreadBenchmarkSpec(
                benchmark_spec.BenchmarkSpec({}, 'name', 'uid'))

            vm_spec = virtual_machine.BaseVmSpec('test_vm_spec.AZURE',
                                                 zone='East US 2',
                                                 machine_type=machine_type)
            vm = azure_virtual_machine.DebianBasedAzureVirtualMachine(vm_spec)

            azure_disk.AzureDisk.Create = mock.Mock()
            azure_disk.AzureDisk.Attach = mock.Mock()
            vm.CreateScratchDisk(disk_spec)

            self.assertEqual(
                vm.scratch_disks[0].metadata, {
                    disk.MEDIA: goal_media,
                    disk.REPLICATION: goal_replication,
                    disk.LEGACY_DISK_TYPE: goal_legacy_disk_type
                })
Example #6
0
    def CreateVirtualMachineFromNodeSection(self, node_section, node_name):
        """Create a VirtualMachine object from NodeSection.

    Args:
      node_section: A dictionary of (option name, option value) pairs.
      node_name: The name of node.
    """
        zone = node_section['zone'] if 'zone' in node_section else self.zones[0]
        if zone not in self.zones:
            self.zones.append(zone)
        if node_section['image'] not in self.image:
            self.image.append(node_section['image'])
        if node_section['vm_type'] not in self.machine_type:
            self.machine_type.append(node_section['vm_type'])
        if zone not in self.networks:
            network_class = CLASSES[self.cloud][NETWORK]
            self.networks[zone] = network_class(zone)
        vm_spec = virtual_machine.BaseVirtualMachineSpec(
            self.project, zone, node_section['vm_type'], node_section['image'],
            self.networks[zone])
        vm_class = CLASSES[self.cloud][VIRTUAL_MACHINE]
        vms = [vm_class(vm_spec) for _ in range(int(node_section['count']))]
        self.vms.extend(vms)
        self.vm_dict[node_name].extend(vms)
        # Create disk spec.
        for option in node_section:
            if option.startswith(ini_constants.OPTION_PD_PREFIX):
                # Create disk spec.
                disk_size, disk_type, mnt_point = node_section[option].split(
                    ':')
                disk_size = int(disk_size)
                disk_spec = disk.BaseDiskSpec(disk_size, disk_type, mnt_point)
                for vm in vms:
                    vm.disk_specs.append(disk_spec)
    def __init__(self, vm_spec):
        """Initialize an Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVmSpec object of the vm.
    """
        super(AzureVirtualMachine, self).__init__(vm_spec)
        self.network = azure_network.AzureNetwork.GetNetwork(self)
        self.firewall = azure_network.AzureFirewall.GetFirewall()
        self.max_local_disks = NUM_LOCAL_VOLUMES.get(self.machine_type) or 1
        self._lun_counter = itertools.count()
        self._deleted = False

        self.resource_group = azure_network.GetResourceGroup()
        self.public_ip = AzurePublicIPAddress(self.zone,
                                              self.name + '-public-ip')
        self.nic = AzureNIC(self.network.subnet, self.name + '-nic',
                            self.public_ip.name,
                            vm_spec.accelerated_networking)
        self.storage_account = self.network.storage_account
        self.image = vm_spec.image or self.IMAGE_URN

        disk_spec = disk.BaseDiskSpec('azure_os_disk')
        self.os_disk = azure_disk.AzureDisk(disk_spec,
                                            self.name,
                                            self.machine_type,
                                            self.storage_account,
                                            None,
                                            is_image=True)
Example #8
0
 def setUp(self):
     p = mock.patch(util.__name__ + '.IssueRetryableCommand')
     p.start()
     self.addCleanup(p.stop)
     self.disk = aws_disk.AwsDisk(disk.BaseDiskSpec(None, None, None),
                                  'zone-a')
     self.disk.id = 'vol-foo'
Example #9
0
def Prepare(benchmark_spec):
  """Install Cassandra and Java on target vms.

  Args:
    benchmark_spec: The benchmark specification. Contains all data that is
        required to run the benchmark.
  """
  vm_dict = benchmark_spec.vm_dict
  logging.info('VM dictionary %s', vm_dict)

  if vm_dict['default']:
    logging.info('No config file is provided, use default settings: '
                 '1 loader node, 3 data nodes')
    vm_dict[LOADER_NODE] = [vm_dict['default'][-1]]
    vm_dict[DATA_NODE] = vm_dict['default'][:3]
    disk_spec = disk.BaseDiskSpec(
        FLAGS.scratch_disk_size,
        FLAGS.scratch_disk_type,
        '/cassandra_data')
    for vm in vm_dict[DATA_NODE]:
      vm.CreateScratchDisk(disk_spec)

  logging.info('Authorizing loader[0] permission to access all other vms.')
  vm_dict[LOADER_NODE][0].AuthenticateVm()

  logging.info('Preparing data files and Java on all vms.')
  vm_util.RunThreaded(lambda vm: vm.Install('cassandra'), benchmark_spec.vms)
  seed_vm = vm_dict[DATA_NODE][0]
  configure = functools.partial(cassandra.Configure, seed_vms=[seed_vm])
  vm_util.RunThreaded(configure, vm_dict[DATA_NODE])
  cassandra.StartCluster(seed_vm, vm_dict[DATA_NODE][1:])
Example #10
0
 def testDeviceId(self):
     with mock.patch(disk.__name__ + '.FLAGS') as disk_flags:
         disk_flags.os_type = 'windows'
         disk_spec = disk.BaseDiskSpec(_COMPONENT, disk_number=1, disk_size=2,
                                       disk_type=gce_disk.PD_STANDARD)
         disk_obj = gce_disk.GceDisk(disk_spec, 'name', 'zone', 'project')
         self.assertEquals(disk_obj.GetDeviceId(), r'\\.\PHYSICALDRIVE1')
Example #11
0
    def __init__(self, vm_spec):
        """Initialize an Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(AzureVirtualMachine, self).__init__(vm_spec)
        self.network = azure_network.AzureNetwork.GetNetwork(self)
        self.firewall = azure_network.AzureFirewall.GetFirewall()
        self.max_local_disks = 1

        self.resource_group = azure_network.GetResourceGroup()
        self.public_ip = AzurePublicIPAddress(self.zone,
                                              self.name + '-public-ip')
        self.nic = AzureNIC(self.network.subnet, self.name + '-nic')
        self.storage_account = self.network.storage_account
        self.image = vm_spec.image or self.IMAGE_URN

        disk_spec = disk.BaseDiskSpec('azure_os_disk')
        self.os_disk = azure_disk.AzureDisk(disk_spec,
                                            self.name,
                                            self.machine_type,
                                            self.storage_account,
                                            None,
                                            is_image=True)
  def DoAzureDiskTest(self, storage_type, disk_type, machine_type,
                      goal_media, goal_replication,
                      goal_host_caching, disk_size=2,
                      goal_size=2, goal_stripes=1):
    with mock.patch(azure_disk.__name__ + '.FLAGS') as disk_flags:
      disk_flags.azure_storage_type = storage_type
      disk_flags.azure_host_caching = goal_host_caching
      disk_spec = disk.BaseDiskSpec(_COMPONENT, disk_size=disk_size,
                                    disk_type=disk_type,
                                    num_striped_disks=goal_stripes)

      vm_spec = virtual_machine.BaseVmSpec(
          'test_vm_spec.AZURE', zone='East US 2', machine_type=machine_type)
      vm = azure_virtual_machine.DebianBasedAzureVirtualMachine(
          vm_spec)

      azure_disk.AzureDisk.Create = mock.Mock()
      azure_disk.AzureDisk.Attach = mock.Mock()
      vm.StripeDisks = mock.Mock()
      vm.CreateScratchDisk(disk_spec)

      expected = {disk.MEDIA: goal_media,
                  disk.REPLICATION: goal_replication,
                  'num_stripes': goal_stripes,
                  'size': goal_size}
      if goal_host_caching:
        expected[azure_disk.HOST_CACHING] = goal_host_caching
      self.assertDictContainsSubset(expected, vm.scratch_disks[0].metadata)
    def __init__(self, vm_spec):
        """Initialize an Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVmSpec object of the vm.
    """
        super(AzureVirtualMachine, self).__init__(vm_spec)

        # PKB zone can be either a region or a region with an availability zone.
        # Format for Azure availability zone support is "region-availability_zone"
        # Example: eastus2-1 is Azure region eastus2 with availability zone 1.

        self.region = util.GetRegionFromZone(self.zone)
        self.availability_zone = util.GetAvailabilityZoneFromZone(self.zone)
        self.use_dedicated_host = vm_spec.use_dedicated_host
        self.num_vms_per_host = vm_spec.num_vms_per_host
        self.network = azure_network.AzureNetwork.GetNetwork(self)
        self.firewall = azure_network.AzureFirewall.GetFirewall()
        self.max_local_disks = NUM_LOCAL_VOLUMES.get(self.machine_type) or 1
        self._lun_counter = itertools.count()
        self._deleted = False

        self.resource_group = azure_network.GetResourceGroup()
        self.public_ip = AzurePublicIPAddress(self.region,
                                              self.availability_zone,
                                              self.name + '-public-ip')
        self.nic = AzureNIC(self.network.subnet, self.name + '-nic',
                            self.public_ip.name,
                            vm_spec.accelerated_networking, self.network.nsg)
        self.storage_account = self.network.storage_account
        if vm_spec.image:
            self.image = vm_spec.image
        elif self.machine_type in _MACHINE_TYPES_ONLY_SUPPORT_GEN2_IMAGES:
            if hasattr(type(self), 'GEN2_IMAGE_URN'):
                self.image = type(self).GEN2_IMAGE_URN
            else:
                raise errors.Benchmarks.UnsupportedConfigError(
                    'No Azure gen2 image.')
        else:
            self.image = type(self).IMAGE_URN

        self.host = None
        if self.use_dedicated_host:
            self.host_series_sku = _GetSkuType(self.machine_type)
            self.host_list = None
        self.low_priority = vm_spec.low_priority
        self.low_priority_status_code = None
        self.spot_early_termination = False
        self.ultra_ssd_enabled = False

        disk_spec = disk.BaseDiskSpec('azure_os_disk')
        disk_spec.disk_type = (vm_spec.boot_disk_type
                               or self.storage_account.storage_type)
        if vm_spec.boot_disk_size:
            disk_spec.disk_size = vm_spec.boot_disk_size
        self.os_disk = azure_disk.AzureDisk(disk_spec,
                                            self,
                                            None,
                                            is_image=True)
 def testPDStandard(self):
   disk_spec = disk.BaseDiskSpec(_COMPONENT, disk_size=2,
                                 disk_type=gce_disk.PD_STANDARD)
   disk_obj = gce_disk.GceDisk(disk_spec, 'name', 'zone', 'project')
   self.assertDictContainsSubset(
       {disk.MEDIA: disk.HDD, disk.REPLICATION: disk.ZONE},
       disk_obj.metadata
   )
Example #15
0
 def testDefaults(self):
   spec = disk.BaseDiskSpec(_COMPONENT)
   self.assertIsNone(spec.device_path)
   self.assertIsNone(spec.disk_number)
   self.assertIsNone(spec.disk_size)
   self.assertIsNone(spec.disk_type)
   self.assertIsNone(spec.mount_point)
   self.assertEqual(spec.num_striped_disks, 1)
Example #16
0
 def testUnrecognizedOptions(self):
     with self.assertRaises(errors.Config.UnrecognizedOption) as cm:
         disk.BaseDiskSpec(_COMPONENT,
                           color='red',
                           flavor='cherry',
                           texture=None)
     self.assertEqual(str(cm.exception), (
         'Unrecognized options were found in test_component: color, flavor, '
         'texture.'))
Example #17
0
 def testProvidedNone(self):
   spec = disk.BaseDiskSpec(
       _COMPONENT, device_path=None, disk_number=None, disk_size=None,
       disk_type=None, mount_point=None)
   self.assertIsNone(spec.device_path)
   self.assertIsNone(spec.disk_number)
   self.assertIsNone(spec.disk_size)
   self.assertIsNone(spec.disk_type)
   self.assertIsNone(spec.mount_point)
   self.assertEqual(spec.num_striped_disks, 1)
Example #18
0
 def testProvidedValid(self):
   spec = disk.BaseDiskSpec(
       _COMPONENT, device_path='test_device_path', disk_number=1,
       disk_size=75, disk_type='test_disk_type', mount_point='/mountpoint',
       num_striped_disks=2)
   self.assertEqual(spec.device_path, 'test_device_path')
   self.assertEqual(spec.disk_number, 1)
   self.assertEqual(spec.disk_size, 75)
   self.assertEqual(spec.disk_type, 'test_disk_type')
   self.assertEqual(spec.mount_point, '/mountpoint')
   self.assertEqual(spec.num_striped_disks, 2)
Example #19
0
 def testPDStandard(self):
     disk_spec = disk.BaseDiskSpec(_COMPONENT,
                                   disk_size=2,
                                   disk_type=gce_disk.PD_STANDARD)
     disk_obj = gce_disk.GceDisk(disk_spec, 'name', 'zone', 'project')
     self.assertEquals(
         disk_obj.metadata, {
             disk.MEDIA: disk.HDD,
             disk.REPLICATION: disk.ZONE,
             disk.LEGACY_DISK_TYPE: disk.STANDARD
         })
    def __init__(self, vm_spec):
        """Initialize a GCE virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(GceVirtualMachine, self).__init__(vm_spec)
        disk_spec = disk.BaseDiskSpec(BOOT_DISK_SIZE_GB, BOOT_DISK_TYPE, None)
        self.boot_disk = gce_disk.GceDisk(disk_spec, self.name, self.zone,
                                          self.project, self.image)
        self.max_local_disks = FLAGS.gce_num_local_ssds
        self.local_disk_counter = 0
  def __init__(self, vm_spec):
    """Initialize a GCE virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
    super(GceVirtualMachine, self).__init__(vm_spec)
    self.name = 'perfkit-%s-%s' % (FLAGS.run_uri, self.instance_counter)
    GceVirtualMachine.instance_counter += 1
    disk_spec = disk.BaseDiskSpec(BOOT_DISK_SIZE_GB, BOOT_DISK_TYPE, None)
    self.boot_disk = gce_disk.GceDisk(
        disk_spec, self.name, self.zone, self.project, self.image)
    self.num_ssds = FLAGS.gce_num_local_ssds
    def __init__(self, vm_spec):
        """Initialize a Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(AzureVirtualMachine, self).__init__(vm_spec)
        self.name = 'perfkit-%s-%s' % (FLAGS.run_uri, self.instance_counter)
        AzureVirtualMachine.instance_counter += 1
        self.service = AzureService(self.name,
                                    self.network.affinity_group.name)
        disk_spec = disk.BaseDiskSpec(None, None, None)
        self.os_disk = azure_disk.AzureDisk(disk_spec, self.name)
Example #23
0
    def __init__(self, vm_spec):
        """Initialize a Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(AzureVirtualMachine, self).__init__(vm_spec)
        self.service = AzureService(self.name,
                                    self.network.affinity_group.name)
        disk_spec = disk.BaseDiskSpec(None, None, None)
        self.os_disk = azure_disk.AzureDisk(disk_spec, self.name)
        self.max_local_disks = 1
        self.local_disk_counter = 0
    def __init__(self,
                 component_full_name,
                 ip_address=None,
                 user_name=None,
                 ssh_private_key=None,
                 internal_ip=None,
                 ssh_port=22,
                 password=None,
                 disk_specs=None,
                 os_type=None,
                 tag=None,
                 zone=None,
                 **kwargs):
        """Initialize the StaticVmSpec object.

    Args:
      component_full_name: string. Fully qualified name of the configurable
          component containing the config options.
      ip_address: The public ip address of the VM.
      user_name: The username of the VM that the keyfile corresponds to.
      ssh_private_key: The absolute path to the private keyfile to use to ssh
          to the VM.
      internal_ip: The internal ip address of the VM.
      ssh_port: The port number to use for SSH and SCP commands.
      password: The password used to log into the VM (Windows Only).
      disk_specs: None or a list of dictionaries containing kwargs used to
          create disk.BaseDiskSpecs.
      os_type: The OS type of the VM. See the flag of the same name for more
          information.
      tag: A string that allows the VM to be included or excluded from a run
          by using the 'static_vm_tags' flag.
      zone: The VM's zone.
      **kwargs: Other args for the superclass.
    """
        super(StaticVmSpec, self).__init__(component_full_name, **kwargs)
        self.ip_address = ip_address
        self.user_name = user_name
        self.ssh_private_key = ssh_private_key
        self.internal_ip = internal_ip
        self.ssh_port = ssh_port
        self.password = password
        self.os_type = os_type
        self.tag = tag
        self.zone = zone
        self.disk_specs = [
            disk.BaseDiskSpec('{0}.disk_specs[{1}]'.format(
                component_full_name, i),
                              flag_values=kwargs.get('flag_values'),
                              **disk_spec)
            for i, disk_spec in enumerate(disk_specs or ())
        ]
    def __init__(self, vm_spec):
        """Initialize an Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVmSpec object of the vm.
    """
        super(AzureVirtualMachine, self).__init__(vm_spec)

        # PKB zone can be either a location or a location with an availability zone.
        # Format for Azure availability zone support is "location-availability_zone"
        # Example: eastus2-1 is Azure location eastus2 with availability zone 1.

        self.location = util.GetLocationFromZone(self.zone)
        self.availability_zone = util.GetAvailabilityZoneFromZone(self.zone)
        self.use_dedicated_host = vm_spec.use_dedicated_host
        # TODO(buggay): implement num_vms_per_host functionality
        self.num_vms_per_host = vm_spec.num_vms_per_host
        if self.num_vms_per_host:
            raise NotImplementedError(
                'Num vms per host for Azure is not supported.')
        self.network = azure_network.AzureNetwork.GetNetwork(self)
        self.firewall = azure_network.AzureFirewall.GetFirewall()
        self.max_local_disks = NUM_LOCAL_VOLUMES.get(self.machine_type) or 1
        self._lun_counter = itertools.count()
        self._deleted = False

        self.resource_group = azure_network.GetResourceGroup()
        self.public_ip = AzurePublicIPAddress(self.location,
                                              self.availability_zone,
                                              self.name + '-public-ip')
        self.nic = AzureNIC(self.network.subnet, self.name + '-nic',
                            self.public_ip.name,
                            vm_spec.accelerated_networking)
        self.storage_account = self.network.storage_account
        self.image = vm_spec.image or self.IMAGE_URN
        self.host = None
        if self.use_dedicated_host:
            self.host_series_sku = _GetSkuType(self.machine_type)
            self.host_list = None

        disk_spec = disk.BaseDiskSpec('azure_os_disk')
        disk_spec.disk_type = (vm_spec.boot_disk_type
                               or self.storage_account.storage_type)
        if vm_spec.boot_disk_size:
            disk_spec.disk_size = vm_spec.boot_disk_size
        self.os_disk = azure_disk.AzureDisk(disk_spec,
                                            self.name,
                                            self.machine_type,
                                            self.storage_account,
                                            None,
                                            is_image=True)
Example #26
0
  def __init__(self, vm_spec):
    """Initialize a Azure virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
    super(AzureVirtualMachine, self).__init__(vm_spec)
    self.network = azure_network.AzureNetwork.GetNetwork(self)
    self.firewall = azure_network.AzureFirewall.GetFirewall()
    self.service = AzureService(self.name,
                                self.network.affinity_group.name)
    disk_spec = disk.BaseDiskSpec('azure_os_disk')
    self.os_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type)
    self.max_local_disks = 1
Example #27
0
    def testScratchDisks(self):
        """Test for creating and deleting scratch disks.

    This test creates two scratch disks on a vm and deletes them, ensuring
    that the proper calls to create, format, mount, and delete are made.
    """

        vm = self._CreateVm()

        disk_spec = disk.BaseDiskSpec(None, None, '/mountpoint0')
        vm.CreateScratchDisk(disk_spec)

        assert len(vm.scratch_disks) == 1, 'Disk not added to scratch disks.'

        scratch_disk = vm.scratch_disks[0]

        scratch_disk.Create.assert_called_once_with()
        vm.FormatDisk.assert_called_once_with(scratch_disk.GetDevicePath())
        vm.MountDisk.assert_called_once_with(scratch_disk.GetDevicePath(),
                                             '/mountpoint0')

        disk_spec = disk.BaseDiskSpec(None, None, '/mountpoint1')
        vm.CreateScratchDisk(disk_spec)

        assert len(vm.scratch_disks) == 2, 'Disk not added to scratch disks.'

        scratch_disk = vm.scratch_disks[1]

        scratch_disk.Create.assert_called_once_with()
        vm.FormatDisk.assert_called_with(scratch_disk.GetDevicePath())
        vm.MountDisk.assert_called_with(scratch_disk.GetDevicePath(),
                                        '/mountpoint1')

        vm.DeleteScratchDisks()

        vm.scratch_disks[0].Delete.assert_called_once_with()
        vm.scratch_disks[1].Delete.assert_called_once_with()
Example #28
0
 def testPresentFlagsOverrideConfigs(self):
   flags = mock_flags.MockFlags()
   flags['data_disk_size'].Parse(100)
   flags['data_disk_type'].Parse('flag_disk_type')
   flags['num_striped_disks'].Parse(3)
   flags['scratch_dir'].Parse('/flag_scratch_dir')
   spec = disk.BaseDiskSpec(
       _COMPONENT, flags, device_path='config_device_path', disk_number=1,
       disk_size=75, disk_type='config_disk_type', mount_point='/mountpoint',
       num_striped_disks=2)
   self.assertEqual(spec.device_path, 'config_device_path')
   self.assertEqual(spec.disk_number, 1)
   self.assertEqual(spec.disk_size, 100)
   self.assertEqual(spec.disk_type, 'flag_disk_type')
   self.assertEqual(spec.mount_point, '/flag_scratch_dir')
   self.assertEqual(spec.num_striped_disks, 3)
Example #29
0
 def testNonPresentFlagsDoNotOverrideConfigs(self):
   flags = mock_flags.MockFlags()
   flags['data_disk_size'].value = 100
   flags['data_disk_type'].value = 'flag_disk_type'
   flags['num_striped_disks'].value = 3
   flags['scratch_dir'].value = '/flag_scratch_dir'
   spec = disk.BaseDiskSpec(
       _COMPONENT, flags, device_path='config_device_path', disk_number=1,
       disk_size=75, disk_type='config_disk_type', mount_point='/mountpoint',
       num_striped_disks=2)
   self.assertEqual(spec.device_path, 'config_device_path')
   self.assertEqual(spec.disk_number, 1)
   self.assertEqual(spec.disk_size, 75)
   self.assertEqual(spec.disk_type, 'config_disk_type')
   self.assertEqual(spec.mount_point, '/mountpoint')
   self.assertEqual(spec.num_striped_disks, 2)
    def __init__(self, vm_spec):
        """Initialize a GCE virtual machine.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(GceVirtualMachine, self).__init__(vm_spec)
        disk_spec = disk.BaseDiskSpec(self.BOOT_DISK_SIZE_GB,
                                      self.BOOT_DISK_TYPE, None)
        self.network = gce_network.GceNetwork.GetNetwork(None)
        self.boot_disk = gce_disk.GceDisk(disk_spec, self.name, self.zone,
                                          self.project, self.image)
        self.max_local_disks = FLAGS.gce_num_local_ssds
        self.boot_metadata = {}

        self.preemptible = FLAGS.gce_preemptible_vms

        events.sample_created.connect(self.AnnotateSample, weak=False)