def setUp(self): super(AwsVirtualMachineTestCase, self).setUp() FLAGS.cloud = providers.AWS FLAGS.os_type = os_types.DEBIAN FLAGS.run_uri = 'aaaaaa' FLAGS.temp_dir = 'tmp' p = mock.patch('perfkitbenchmarker.providers.aws.' 'util.IssueRetryableCommand') p.start() self.addCleanup(p.stop) p2 = mock.patch('perfkitbenchmarker.' 'vm_util.IssueCommand') p2.start() self.addCleanup(p2.stop) # VM Creation depends on there being a BenchmarkSpec. config_spec = benchmark_config_spec.BenchmarkConfigSpec( _BENCHMARK_NAME, flag_values=FLAGS, vm_groups={}) self.spec = benchmark_spec.BenchmarkSpec(mock.MagicMock(), config_spec, _BENCHMARK_UID) self.addCleanup(context.SetThreadBenchmarkSpec, None) self.vm = aws_virtual_machine.AwsVirtualMachine( aws_virtual_machine.AwsVmSpec('test_vm_spec.AWS', zone='us-east-1a', machine_type='c3.large', spot_price=123.45)) self.vm.id = 'i-foo' self.vm.image = 'ami-12345' self.vm.client_token = '00000000-1111-2222-3333-444444444444' network_mock = mock.MagicMock() network_mock.subnet = mock.MagicMock(id='subnet-id') placement_group = mock.MagicMock() placement_group.name = 'placement_group_name' placement_group.strategy = 'cluster' network_mock.placement_group = placement_group self.vm.network = network_mock self.vm.placement_group = placement_group self.response = self.open_json_data('aws-describe-instance.json') self.sir_response = self.open_json_data( 'aws-describe-spot-instance-requests.json') self.vm.network.is_static = False self.vm.network.regional_network.vpc.default_security_group_id = 'sg-1234'
def setUp(self): super(GCEVMFlagsTestCase, self).setUp() FLAGS.cloud = providers.GCP FLAGS.gcloud_path = 'test_gcloud' FLAGS.run_uri = 'aaaaaa' FLAGS.gcp_instance_metadata = [] FLAGS.gcp_instance_metadata_from_file = [] # Creating a VM object causes network objects to be added to the current # thread's benchmark spec. Create such a benchmark spec for these tests. self.addCleanup(context.SetThreadBenchmarkSpec, None) config_spec = benchmark_config_spec.BenchmarkConfigSpec( _BENCHMARK_NAME, flag_values=FLAGS, vm_groups={}) self._benchmark_spec = benchmark_spec.BenchmarkSpec( mock.MagicMock(), config_spec, _BENCHMARK_UID) get_tmp_dir_mock = mock.patch(vm_util.__name__ + '.GetTempDir', return_value='TempDir') get_tmp_dir_mock.start() self.addCleanup(get_tmp_dir_mock.stop)
def setUp(self): self._mocked_flags = mock_flags.PatchTestCaseFlags(self) self._mocked_flags.cloud = providers.GCP self._mocked_flags.gcloud_path = 'test_gcloud' self._mocked_flags.os_type = os_types.DEBIAN self._mocked_flags.run_uri = 'aaaaaa' self._mocked_flags.gcp_instance_metadata = [] self._mocked_flags.gcp_instance_metadata_from_file = [] # Creating a VM object causes network objects to be added to the current # thread's benchmark spec. Create such a benchmark spec for these tests. self.addCleanup(context.SetThreadBenchmarkSpec, None) config_spec = benchmark_config_spec.BenchmarkConfigSpec( _BENCHMARK_NAME, flag_values=self._mocked_flags, vm_groups={}) self._benchmark_spec = benchmark_spec.BenchmarkSpec( mock.MagicMock(), config_spec, _BENCHMARK_UID) get_tmp_dir_mock = mock.patch(vm_util.__name__ + '.GetTempDir') get_tmp_dir_mock.start() self.addCleanup(get_tmp_dir_mock.stop)
def testBenchmarkConfigSpecLoadsProvider(self): p = mock.patch(providers.__name__ + '.LoadProvider') p.start() self.addCleanup(p.stop) config = { 'vm_groups': { 'group1': { 'cloud': 'AWS', 'os_type': 'debian', 'vm_count': 0, 'vm_spec': { 'AWS': {} } } } } benchmark_config_spec.BenchmarkConfigSpec('name', flag_values=FLAGS, **config) providers.LoadProvider.assert_called_with('AWS', True)
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' mocked_flags.temp_dir = 'tmp' p = mock.patch('perfkitbenchmarker.providers.aws.' 'util.IssueRetryableCommand') p.start() self.addCleanup(p.stop) p2 = mock.patch('perfkitbenchmarker.' 'vm_util.IssueCommand') p2.start() self.addCleanup(p2.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(mock.MagicMock(), config_spec, _BENCHMARK_UID) self.addCleanup(context.SetThreadBenchmarkSpec, None) self.vm = aws_virtual_machine.AwsVirtualMachine( aws_virtual_machine.AwsVmSpec('test_vm_spec.AWS', zone='us-east-1a', machine_type='c3.large', spot_price=123.45)) self.vm.id = 'i-foo' self.vm.image = 'ami-12345' self.vm.client_token = '00000000-1111-2222-3333-444444444444' network_mock = mock.MagicMock() network_mock.subnet = mock.MagicMock(id='subnet-id') placement_group = mock.MagicMock() placement_group.name = 'placement_group_name' network_mock.placement_group = placement_group self.vm.network = network_mock self.response = self.openJsonData('aws-describe-instance.json') self.sir_response =\ self.openJsonData('aws-describe-spot-instance-requests.json')
def setUp(self): self.saved_flag_values = flagsaver.save_flag_values() self.patches = [] vm_prefix = linux_virtual_machine.__name__ + '.BaseLinuxMixin' self.patches.append( mock.patch(vm_prefix + '.FormatDisk')) self.patches.append( mock.patch(vm_prefix + '.MountDisk')) self.patches.append( mock.patch( util.__name__ + '.GetDefaultProject', side_effect='test_project')) # Patch subprocess.Popen to make sure we don't issue any commands to spin up # resources. self.patches.append(mock.patch('subprocess.Popen')) self.patches.append( mock.patch(vm_util.__name__ + '.GetTempDir', return_value='/tmp/dir')) self._PatchCloudSpecific() for p in self.patches: p.start() self.addCleanup(p.stop) # We need the disk class mocks to return new mocks each time they are # called. Otherwise all "disks" instantiated will be the same object. self._GetDiskClass().side_effect = ( lambda *args, **kwargs: mock.MagicMock(is_striped=False)) # VM Creation depends on there being a BenchmarkSpec. config_spec = benchmark_config_spec.BenchmarkConfigSpec( _BENCHMARK_NAME, flag_values=FLAGS, vm_groups={}) self.spec = benchmark_spec.BenchmarkSpec(mock.MagicMock(), config_spec, _BENCHMARK_UID) self.addCleanup(context.SetThreadBenchmarkSpec, None) self.addCleanup(flagsaver.restore_flag_values, self.saved_flag_values)
def _GetBenchmarkSpec(benchmark_config, benchmark_name, benchmark_uid): """Creates a BenchmarkSpec or loads one from a file. During the provision stage, creates a BenchmarkSpec from the provided configuration. During any later stage, loads the BenchmarkSpec that was created during the provision stage from a file. Args: benchmark_config: A Python dictionary representation of the configuration for the benchmark. For a complete explanation, see perfkitbenchmarker/configs/__init__.py. benchmark_name: string. Name of the benchmark. benchmark_uid: string. Identifies a specific run of a benchmark. Returns: The created or loaded BenchmarkSpec. """ if FLAGS.run_stage in (STAGE_ALL, STAGE_PROVISION): return benchmark_spec.BenchmarkSpec(benchmark_config, benchmark_name, benchmark_uid) else: # TODO(skschneider): Build BenchmarkConfigSpec before RunBenchmark. config = benchmark_config_spec.BenchmarkConfigSpec(benchmark_name, flag_values=FLAGS, **benchmark_config) try: return benchmark_spec.BenchmarkSpec.GetSpecFromFile( benchmark_uid, config) except IOError: if FLAGS.run_stage == STAGE_PREPARE: logging.error( 'We were unable to load the BenchmarkSpec. This may be related ' 'to two additional run stages which have recently been added. ' 'Please make sure to run the stage "provision" before "prepare". ' 'Similarly, make sure to run "teardown" after "cleanup".') raise
def _CreateBenchmarkSpecFromConfigDict(self, config_dict, benchmark_name): config_spec = benchmark_config_spec.BenchmarkConfigSpec( benchmark_name, flag_values=FLAGS, **config_dict) return benchmark_spec.BenchmarkSpec(mock.MagicMock(), config_spec, UID)
def setUp(self): super(GceNetworkTest, self).setUp() # need a benchmarkspec in the context to run config_spec = benchmark_config_spec.BenchmarkConfigSpec( 'cluster_boot', flag_values=FLAGS) benchmark_spec.BenchmarkSpec(mock.Mock(), config_spec, 'uid')
def _CreateBenchmarkSpecFromConfigDict(self, config_dict, benchmark_name): config_spec = benchmark_config_spec.BenchmarkConfigSpec( benchmark_name, flag_values=FLAGS, **config_dict) benchmark_module = next((b for b in linux_benchmarks.BENCHMARKS if b.BENCHMARK_NAME == benchmark_name)) return benchmark_spec.BenchmarkSpec(benchmark_module, config_spec, UID)
def _CreateBenchmarkSpecFromConfigDict(self, config_dict, benchmark_name): config_spec = benchmark_config_spec.BenchmarkConfigSpec( benchmark_name, flag_values=self._mocked_flags, **config_dict) return benchmark_spec.BenchmarkSpec(config_spec, benchmark_name, UID)
def _CreateBenchmarkSpec(self, benchmark_config_yaml): config = configs.LoadConfig(benchmark_config_yaml, {}, NAME) config_spec = benchmark_config_spec.BenchmarkConfigSpec( NAME, flag_values=self._mocked_flags, **config) return benchmark_spec.BenchmarkSpec(config_spec, NAME, UID)
def setUp(self): self.addCleanup(context.SetThreadBenchmarkSpec, None) config_spec = benchmark_config_spec.BenchmarkConfigSpec( _BENCHMARK_NAME, flag_values=mock_flags.MockFlags(), vm_groups={}) self.benchmark_spec = benchmark_spec.BenchmarkSpec( mock.MagicMock(), config_spec, _BENCHMARK_UID)
def _CreateBenchmarkSpec(self, benchmark_config_yaml): config = configs.LoadConfig(benchmark_config_yaml, {}, NAME) config_spec = benchmark_config_spec.BenchmarkConfigSpec( NAME, flag_values=FLAGS, **config) return benchmark_spec.BenchmarkSpec(ping_benchmark, config_spec, UID)