def testMissingGpuCount(self): with self.assertRaises(errors.Config.MissingOption) as cm: virtual_machine.BaseVmSpec(_COMPONENT, flag_values=FLAGS, gpu_type='k80') self.assertEqual(str(cm.exception), ('gpu_count must be specified if gpu_type is set'))
def CreateMockSpec(self, additional_spec_items={}): default_server_disk_spec = aws_disk.AwsDiskSpec(_COMPONENT, disk_size=5, disk_type=aws_disk.IO1, iops=1000) default_server_vm_spec = virtual_machine.BaseVmSpec( 'NAME', **{ 'machine_type': 'db.t1.micro', 'zone': 'us-west-2b' }) spec_dict = { 'engine': MYSQL, 'engine_version': '5.7.11', 'run_uri': '123', 'database_name': 'fakedbname', 'database_password': '******', 'database_username': '******', 'high_availability': False, 'vm_spec': default_server_vm_spec, 'disk_spec': default_server_disk_spec, } spec_dict.update(additional_spec_items) mock_db_spec = Mock(spec=benchmark_config_spec._RelationalDbSpec) mock_db_spec.configure_mock(**spec_dict) return mock_db_spec
def createAuroraMockSpec(self, additional_spec_items={}): default_server_vm_spec = virtual_machine.BaseVmSpec( 'NAME', **{ 'machine_type': 'db.t1.micro', 'zone': 'us-west-2b' }) spec_dict = { 'engine': AURORA_POSTGRES, 'run_uri': '123', 'database_name': 'fakedbname', 'database_password': '******', 'database_username': '******', 'vm_spec': default_server_vm_spec, 'zones': ['us-east-1a', 'us-east-1d'], 'engine_version': '9.6.2', 'high_availability': True } spec_dict.update(additional_spec_items) mock_db_spec = Mock( spec=benchmark_config_spec._ManagedRelationalDbSpec) mock_db_spec.configure_mock(**spec_dict) return mock_db_spec
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 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 })
def testUnrecognizedOptions(self): with self.assertRaises(errors.Config.UnrecognizedOption) as cm: virtual_machine.BaseVmSpec(_COMPONENT, color='red', flavor='cherry', texture=None) self.assertEqual(str(cm.exception), ( 'Unrecognized options were found in test_component: color, flavor, ' 'texture.'))
def setUp(self): mocked_flags = mock_flags.PatchTestCaseFlags(self) mocked_flags.cloud = providers.AWS mocked_flags.os_type = os_types.DEBIAN mocked_flags.run_uri = 'aaaaaa' p = mock.patch('perfkitbenchmarker.providers.aws.' 'util.IssueRetryableCommand') p.start() self.addCleanup(p.stop) # VM Creation depends on there being a BenchmarkSpec. config_spec = benchmark_config_spec.BenchmarkConfigSpec( _BENCHMARK_NAME, flag_values=mocked_flags, vm_groups={}) self.spec = benchmark_spec.BenchmarkSpec(config_spec, _BENCHMARK_NAME, _BENCHMARK_UID) self.addCleanup(context.SetThreadBenchmarkSpec, None) self.vm = aws_virtual_machine.AwsVirtualMachine( virtual_machine.BaseVmSpec('test_vm_spec.AWS', zone='us-east-1a', machine_type='c3.large')) self.vm.id = 'i-foo' path = os.path.join(os.path.dirname(__file__), 'data', 'aws-describe-instance.json') with open(path) as f: self.response = f.read()
def setUp(self): for module in ('perfkitbenchmarker.virtual_machine', 'perfkitbenchmarker.vm_util', 'perfkitbenchmarker.providers.aws.aws_network'): p = mock.patch('{0}.FLAGS'.format(module)) mock_flags = p.start() mock_flags.run_uri = 'aaaaaa' self.addCleanup(p.stop) p = mock.patch('perfkitbenchmarker.providers.aws.' 'util.IssueRetryableCommand') p.start() self.addCleanup(p.stop) # VM Creation depends on there being a BenchmarkSpec. self.spec = benchmark_spec.BenchmarkSpec({}, 'name', 'benchmark_uid') self.addCleanup(context.SetThreadBenchmarkSpec, None) self.vm = aws_virtual_machine.AwsVirtualMachine( virtual_machine.BaseVmSpec('test_vm_spec.AWS', zone='us-east-1a', machine_type='c3.large')) self.vm.id = 'i-foo' path = os.path.join(os.path.dirname(__file__), 'data', 'aws-describe-instance.json') with open(path) as f: self.response = f.read()
def create_virtual_machine_spec(): spec = virtual_machine.BaseVmSpec(_COMPONENT, image='test_image', install_packages=False, machine_type='test_machine_type', zone='test_zone') return spec
def testGpus(self): gpu_count = 2 gpu_type = 'k80' result = virtual_machine.BaseVmSpec(_COMPONENT, gpu_count=gpu_count, gpu_type=gpu_type) self.assertEqual(result.gpu_type, 'k80') self.assertEqual(result.gpu_count, 2)
def testProvidedValid(self): spec = virtual_machine.BaseVmSpec( _COMPONENT, image='test_image', install_packages=False, machine_type='test_machine_type', zone='test_zone') self.assertEqual(spec.image, 'test_image') self.assertEqual(spec.install_packages, False) self.assertEqual(spec.machine_type, 'test_machine_type') self.assertEqual(spec.zone, 'test_zone')
def testInvalidGpuCount(self): with self.assertRaises(errors.Config.InvalidValue) as cm: virtual_machine.BaseVmSpec( _COMPONENT, flag_values=FLAGS, gpu_count=0, gpu_type='k80') self.assertEqual(str(cm.exception), ( 'Invalid test_component.gpu_count value: "0". ' 'Value must be at least 1.'))
def create_virtual_machine_spec(): spec = virtual_machine.BaseVmSpec( _COMPONENT, image='nvidia/cuda:8.0-devel-ubuntu16.04', install_packages=False, machine_type='test_machine_type', zone='test_zone') return spec
def testMissingGpuType(self): flags = mock_flags.MockFlags() with self.assertRaises(errors.Config.MissingOption) as cm: virtual_machine.BaseVmSpec(_COMPONENT, flag_values=flags, gpu_count=1) self.assertEqual(str(cm.exception), ( 'gpu_type must be specified if gpu_count is set'))
def CreateMockClientVM(db_class): client_vm_spec = virtual_machine.BaseVmSpec( 'NAME', **{ 'machine_type': 'n1-standard-16', 'zone': 'us-west1-b', }) client_vm_spec.HasIpAddress = True client_vm_spec.ip_address = '192.168.0.1' db_class.client_vm = client_vm_spec
def testInvalidGpuType(self): with self.assertRaises(errors.Config.InvalidValue) as cm: virtual_machine.BaseVmSpec( _COMPONENT, flag_values=FLAGS, gpu_count=1, gpu_type='bad_type') self.assertIn(( 'Invalid test_component.gpu_type value: "bad_type". ' 'Value must be one of the following:'), str(cm.exception)) self.assertIn('k80', str(cm.exception)) self.assertIn('p100', str(cm.exception))
def createMySQLSpecDict(self): vm_spec = virtual_machine.BaseVmSpec( 'NAME', **{'machine_type': 'db-n1-standard-1'}) disk_spec = disk.BaseDiskSpec('NAME', **{'disk_size': 50}) # TODO: Database version has more than one supported value. Test should # reflect that by not declaring a database version and letting the default # version be returned. return { 'database': MYSQL, 'database_version': '5.7', 'run_uri': '123', 'database_name': 'fakedbname', 'database_password': '******', 'vm_spec': vm_spec, 'disk_spec': disk_spec, 'high_availability': False, 'backup_enabled': True, 'backup_start_time': '07:00', }
def doAwsDiskTest(self, disk_type, machine_type, goal_media, goal_replication, goal_legacy_disk_type): disk_spec = aws_disk.AwsDiskSpec(_COMPONENT, disk_size=2, disk_type=disk_type) vm_spec = virtual_machine.BaseVmSpec('test_vm_spec.AWS', zone='us-east-1a', machine_type=machine_type) vm = aws_virtual_machine.DebianBasedAwsVirtualMachine(vm_spec) 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 })
def createMySQLSpecDict(self): vm_spec = virtual_machine.BaseVmSpec( 'NAME', **{ 'machine_type': 'db-n1-standard-1', 'zone': 'us-west1-b', }) disk_spec = disk.BaseDiskSpec('NAME', **{'disk_size': 50}) return { 'engine': MYSQL, 'engine_version': '5.7', 'run_uri': '123', 'database_name': 'fakedbname', 'database_password': '******', 'vm_spec': vm_spec, 'disk_spec': disk_spec, 'high_availability': False, 'backup_enabled': True, 'backup_start_time': '07:00', }
def doAwsDiskTest(self, disk_type, machine_type, goal_media, goal_replication, goal_legacy_disk_type): disk_spec = aws_disk.AwsDiskSpec(disk_size=2, disk_type=disk_type, mount_point=None) context.SetThreadBenchmarkSpec( benchmark_spec.BenchmarkSpec({}, 'name', 'uid')) vm_spec = virtual_machine.BaseVmSpec('test_vm_spec.AWS', zone='us-east-1a', machine_type=machine_type) vm = aws_virtual_machine.DebianBasedAwsVirtualMachine(vm_spec) 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 })
def createSpecDict(self): disk_spec = aws_disk.AwsDiskSpec(_COMPONENT, disk_size=5, disk_type=aws_disk.IO1, iops=1000) vm_spec = virtual_machine.BaseVmSpec( 'NAME', **{ 'machine_type': 'db.t1.micro', 'zone': 'us-west-2b' }) return { 'database': MYSQL, 'database_version': '5.7.11', 'run_uri': '123', 'database_name': 'fakedbname', 'database_password': '******', 'database_username': '******', 'vm_spec': vm_spec, 'disk_spec': disk_spec, 'high_availability': False }
def _CreateVm(self): vm_spec = virtual_machine.BaseVmSpec('test_vm_spec.Azure') return azure_virtual_machine.DebianBasedAzureVirtualMachine(vm_spec)
def __init__(self, _): super(LinuxVMResource, self).__init__(virtual_machine.BaseVmSpec('test'))
def testInvalidZone(self): with self.assertRaises(errors.Config.InvalidValue): virtual_machine.BaseVmSpec(_COMPONENT, zone=0)
def testInvalidMachineType(self): with self.assertRaises(errors.Config.InvalidValue): virtual_machine.BaseVmSpec(_COMPONENT, machine_type=True)
def testInvalidInstallPackages(self): with self.assertRaises(errors.Config.InvalidValue): virtual_machine.BaseVmSpec(_COMPONENT, install_packages='yes')
def testDefaults(self): spec = virtual_machine.BaseVmSpec(_COMPONENT) self.assertEqual(spec.image, None) self.assertEqual(spec.install_packages, True) self.assertEqual(spec.machine_type, None) self.assertEqual(spec.zone, None)
def _CreateVm(self): vm_spec = virtual_machine.BaseVmSpec('test_vm_spec.AWS', zone='us-east-1a') return aws_virtual_machine.DebianBasedAwsVirtualMachine(vm_spec)