def testReadFromFile_NoErr(self): s = ('[{' ' "ip_address": "174.12.14.1", ' ' "user_name": "perfkitbenchmarker", ' ' "keyfile_path": "perfkitbenchmarker.pem" ' '}, ' '{ ' ' "ip_address": "174.12.14.121", ' ' "user_name": "ubuntu", ' ' "keyfile_path": "rackspace.pem", ' ' "internal_ip": "10.10.10.2", ' ' "zone": "rackspace_dallas" ' '}] ') fp = StringIO(s) svm.StaticVirtualMachine.ReadStaticVirtualMachineFile(fp) vm_pool = svm.StaticVirtualMachine.vm_pool self.assertEqual(2, len(vm_pool)) self._AssertStaticVMsEqual( svm.StaticVirtualMachine( svm.StaticVmSpec(_COMPONENT, ip_address='174.12.14.1', user_name='perfkitbenchmarker', ssh_private_key='perfkitbenchmarker.pem')), vm_pool[0]) self._AssertStaticVMsEqual( svm.StaticVirtualMachine( svm.StaticVmSpec(_COMPONENT, ip_address='174.12.14.121', user_name='ubuntu', ssh_private_key='rackspace.pem', internal_ip='10.10.10.2', zone='rackspace_dallas')), vm_pool[1])
def testYumInstallRaisesNotImplementedError(self): static_vm_spec = static_virtual_machine.StaticVmSpec( 'test_static_vm_spec') self.mock_vm = static_virtual_machine.Rhel7BasedStaticVirtualMachine( static_vm_spec) self.mock_vm.install_packages = True with self.assertRaises(NotImplementedError): self.mock_vm.Install('openfoam')
def testDiskSpecs(self): spec = svm.StaticVmSpec(_COMPONENT, disk_specs=_DISK_SPEC_DICTS) self.assertEqual(len(spec.disk_specs), 2) for disk_spec in spec.disk_specs: self.assertIsInstance(disk_spec, disk.BaseDiskSpec) self.assertEqual(spec.disk_specs[0].device_path, '/test_device_path') self.assertIsNone(spec.disk_specs[0].mount_point) self.assertIsNone(spec.disk_specs[1].device_path) self.assertEqual(spec.disk_specs[1].mount_point, '/test_mount_point')
def testDefaults(self): spec = svm.StaticVmSpec(_COMPONENT) self.assertIsNone(spec.ip_address) self.assertIsNone(spec.user_name) self.assertIsNone(spec.ssh_private_key) self.assertIsNone(spec.internal_ip) self.assertEqual(spec.ssh_port, 22) self.assertIsNone(spec.password) self.assertIsNone(spec.os_type) self.assertEqual(spec.disk_specs, [])
def testReadFromFile_UnknownOsTypeDefaultsToLinuxRequiredKeys(self): FLAGS.os_type = 'unknown_os_type' s = ('[{' ' "ip_address": "174.12.14.1", ' ' "user_name": "perfkitbenchmarker", ' ' "keyfile_path": "perfkitbenchmarker.pem"' '}]') fp = StringIO(s) svm.StaticVirtualMachine.ReadStaticVirtualMachineFile(fp) vm_pool = svm.StaticVirtualMachine.vm_pool self.assertEqual(1, len(vm_pool)) self._AssertStaticVMsEqual( svm.StaticVirtualMachine( svm.StaticVmSpec(_COMPONENT, ip_address='174.12.14.1', user_name='perfkitbenchmarker', ssh_private_key='perfkitbenchmarker.pem')), vm_pool[0])
def Decode(self, value, component_full_name, flag_values): """Decodes an item of the static_vms list of a VM group config object. Args: value: dict mapping static VM config option name string to corresponding option value. component_full_name: string. Fully qualified name of the configurable component containing the config option. flag_values: flags.FlagValues. Runtime flag values to be propagated to BaseSpec constructors. Returns: StaticVmSpec decoded from the input dict. Raises: errors.Config.InvalidValue upon invalid input value. """ input_dict = super(_StaticVmDecoder, self).Decode( value, component_full_name, flag_values) return static_virtual_machine.StaticVmSpec( self._GetOptionFullName(component_full_name), **input_dict)
def ConstructVirtualMachines(self): """Constructs the BenchmarkSpec's VirtualMachine objects.""" vm_group_specs = self.config[VM_GROUPS] zone_index = 0 for group_name, group_spec in vm_group_specs.iteritems(): vms = [] vm_count = group_spec.get(VM_COUNT, DEFAULT_COUNT) if vm_count is None: vm_count = FLAGS.num_vms disk_count = group_spec.get(DISK_COUNT, DEFAULT_COUNT) try: # First create the Static VMs. if STATIC_VMS in group_spec: static_vm_specs = group_spec[STATIC_VMS][:vm_count] for static_vm_spec_index, spec_kwargs in enumerate( static_vm_specs): vm_spec = static_vm.StaticVmSpec( '{0}.{1}.{2}.{3}[{4}]'.format( self.name, VM_GROUPS, group_name, STATIC_VMS, static_vm_spec_index), **spec_kwargs) static_vm_class = static_vm.GetStaticVmClass( vm_spec.os_type) vms.append(static_vm_class(vm_spec)) os_type = self._GetOsTypeForGroup(group_name) cloud = self._GetCloudForGroup(group_name) providers.LoadProvider(cloud.lower()) # This throws an exception if the benchmark is not # supported. self._CheckBenchmarkSupport(cloud) # Then create a VmSpec and possibly a DiskSpec which we can # use to create the remaining VMs. vm_spec_class = virtual_machine.GetVmSpecClass(cloud) vm_spec = vm_spec_class( '.'.join( (self.name, VM_GROUPS, group_name, VM_SPEC, cloud)), FLAGS, **group_spec[VM_SPEC][cloud]) if DISK_SPEC in group_spec: disk_spec_class = disk.GetDiskSpecClass(cloud) disk_spec = disk_spec_class(**group_spec[DISK_SPEC][cloud]) disk_spec.ApplyFlags(FLAGS) # disk_spec.disk_type may contain legacy values that were # copied from FLAGS.scratch_disk_type into # FLAGS.data_disk_type at the beginning of the run. We # translate them here, rather than earlier, because here is # where we know what cloud we're using and therefore we're # able to pick the right translation table. disk_spec.disk_type = disk.WarnAndTranslateDiskTypes( disk_spec.disk_type, cloud) else: disk_spec = None except TypeError as e: # This is what we get if one of the kwargs passed into a spec's # __init__ method was unexpected. raise ValueError( 'Config contained an unexpected parameter. Error message:\n%s' % e) # Create the remaining VMs using the specs we created earlier. for _ in xrange(vm_count - len(vms)): # Assign a zone to each VM sequentially from the --zones flag. if FLAGS.zones: vm_spec.zone = FLAGS.zones[zone_index] zone_index = (zone_index + 1 if zone_index < len(FLAGS.zones) - 1 else 0) vm = self._CreateVirtualMachine(vm_spec, os_type, cloud) if disk_spec: vm.disk_specs = [ copy.copy(disk_spec) for _ in xrange(disk_count) ] # In the event that we need to create multiple disks from the same # DiskSpec, we need to ensure that they have different mount points. if (disk_count > 1 and disk_spec.mount_point): for i, spec in enumerate(vm.disk_specs): spec.mount_point += str(i) vms.append(vm) self.vm_groups[group_name] = vms self.vms.extend(vms)
def CreateTestStaticVm(): vm_spec = svm.StaticVmSpec(_COMPONENT) return TestStaticVirtualMachine(vm_spec=vm_spec)