Repository: googlecloudplatform/perfkitbenchmarker
Issue: Problem running on Windows VMs

Running any benchmark with Windows VMs gives me this error:
AttributeError: 'WindowsGceVirtualMachine' object has no attribute 'PrepareBackgroundWorkload'


Changed files:
perfkitbenchmarker/virtual_machine.py, tests/background_workload_test.py, perfkitbenchmarker/vm_util.py

diff --git a/perfkitbenchmarker/virtual_machine.py b/perfkitbenchmarker/virtual_machine.py
index 8f0b6134..6b5dedb8 100644
--- a/perfkitbenchmarker/virtual_machine.py
+++ b/perfkitbenchmarker/virtual_machine.py
@@ -552,3 +552,18 @@ class BaseOsMixin(object):
   def _TestReachable(self, ip):
     """Returns True if the VM can reach the ip address and False otherwise."""
     raise NotImplementedError()
+
+  def StartBackgroundWorkload(self):
+    """Start the background workload"""
+    if self.background_cpu_threads:
+      raise NotImplementedError()
+
+  def StopBackgroundWorkload(self):
+    """Stop the background workoad"""
+    if self.background_cpu_threads:
+      raise NotImplementedError()
+
+  def PrepareBackgroundWorkload(self):
+    """Prepare for the background workload"""
+    if self.background_cpu_threads:
+      raise NotImplementedError()
diff --git a/perfkitbenchmarker/vm_util.py b/perfkitbenchmarker/vm_util.py
index 727cd5cf..2b990b3f 100644
--- a/perfkitbenchmarker/vm_util.py
+++ b/perfkitbenchmarker/vm_util.py
@@ -76,7 +76,7 @@ flags.DEFINE_integer('burn_cpu_threads', 1, 'Number of threads to use to '
                      'burn cpu before starting benchmark.')
 flags.DEFINE_integer('background_cpu_threads', None,
                      'Number of threads of background cpu usage while '
-                     'running benchmark')
+                     'running a benchmark')
 
 
 class IpAddressSubset(object):
diff --git a/tests/background_workload_test.py b/tests/background_workload_test.py
index a7a9a919..08b64f4a 100644
--- a/tests/background_workload_test.py
+++ b/tests/background_workload_test.py
@@ -55,7 +55,7 @@ class TestBackgroundWorkload(unittest.TestCase):
     self.last_call += 1
 
   def setupCommonFlags(self, mock_flags):
-    mock_flags.os_type = 'debian'
+    mock_flags.os_type = benchmark_spec.DEBIAN
     mock_flags.cloud = 'GCP'
 
   def _CheckVMFromSpec(self, spec, num_working):
@@ -110,6 +110,22 @@ class TestBackgroundWorkload(unittest.TestCase):
           self.assertEqual(vm.StartBackgroundWorkload.call_count, 1)
           self.assertEqual(vm.StopBackgroundWorkload.call_count, 1)
 
+  def testWindowsVMCausesError(self):
+    """ windows vm with background_cpu_threads raises exception """
+    with mock_flags.PatchFlags() as mocked_flags:
+      self.setupCommonFlags(mocked_flags)
+      mocked_flags.background_cpu_threads = 1
+      mocked_flags.os_type = benchmark_spec.WINDOWS
+      config = configs.LoadConfig(ping_benchmark.BENCHMARK_CONFIG, {}, NAME)
+      spec = benchmark_spec.BenchmarkSpec(config, NAME, UID)
+      spec.ConstructVirtualMachines()
+      with self.assertRaises(Exception):
+        spec.Prepare()
+      with self.assertRaises(Exception):
+        spec.StartBackgroundWorkload()
+      with self.assertRaises(Exception):
+        spec.StopBackgroundWorkload()
+
   def testBackgroundWorkloadVM(self):
     """ Check that the vm background workload calls work """
     with mock_flags.PatchFlags() as mocked_flags:
@@ -133,6 +149,20 @@ class TestBackgroundWorkload(unittest.TestCase):
         self.assertIsNone(vm.background_cpu_threads)
       self._CheckVMFromSpec(spec, 0)
 
+  def testBackgroundWorkloadWindows(self):
+    """ Test that nothing happens with the vanilla config """
+    with mock_flags.PatchFlags() as mocked_flags:
+      self.setupCommonFlags(mocked_flags)
+      mocked_flags.os_type = benchmark_spec.WINDOWS
+      mocked_flags.background_cpu_threads = None
+      config = configs.LoadConfig(ping_benchmark.BENCHMARK_CONFIG, {}, NAME)
+      spec = benchmark_spec.BenchmarkSpec(config, NAME, UID)
+      spec.ConstructVirtualMachines()
+
+      for vm in spec.vms:
+        self.assertIsNone(vm.background_cpu_threads)
+      self._CheckVMFromSpec(spec, 0)
+
 
   def testBackgroundWorkloadVanillaConfigFlag(self):
     """ Check that the flag overrides the config """