Beispiel #1
0
 def test_save_state_unexpected_oserror(self, mock_makedirs):
     scenario = Scenario()
     scenario.cluster = mock_cluster()
     scenario.output_directory = environment.test_output_dir(self)
     err = OSError()
     err.errno = errno.EIO
     mock_makedirs.side_effect = err
     with self.assertRaises(OSError) as ar:
         scenario.save_state()
     self.assertEqual(errno.EIO, ar.exception.errno)
Beispiel #2
0
 def test_scenario_target_config(self):
   scenario = Scenario(name="Fake Scenario")
   scenario.cluster = mock_cluster()
   scenario.cluster.name.return_value = "fake_cluster"
   vm_group = VMGroup(scenario, "nasty\nvg?nm /\t#$\\")
   mock_vms = [mock.Mock(spec=Vm) for _ in xrange(3)]
   mock_vms[0].vm_name.return_value = "mock_vm_0"
   mock_vms[1].vm_name.return_value = "mock_vm_1"
   mock_vms[2].vm_name.return_value = "mock_vm_2"
   mock_vms[0].vm_ip.return_value = "fake_addr_0"
   mock_vms[1].vm_ip.return_value = "fake_addr_1"
   mock_vms[2].vm_ip.return_value = None
   scenario.vm_groups = {"fake_vm_group": vm_group}
   with mock.patch.object(vm_group, "get_vms") as mock_get_vms:
     mock_get_vms.return_value = mock_vms
     ret = prometheus.scenario_target_config(scenario)
   expected = [
     {
       "labels": {
         "cluster_name": "fake_cluster",
         "instance": "mock_vm_0",
         "job": "xray",
         "scenario_display_name": "Fake Scenario",
         "scenario_id": str(scenario.id),
         "scenario_name": "Fake Scenario",
         "vm_group": "nasty\nvg?nm /\t#$\\",
       },
       "targets": [
         "fake_addr_0:9100",
       ],
     },
     {
       "labels": {
         "cluster_name": "fake_cluster",
         "instance": "mock_vm_1",
         "job": "xray",
         "scenario_display_name": "Fake Scenario",
         "scenario_id": str(scenario.id),
         "scenario_name": "Fake Scenario",
         "vm_group": "nasty\nvg?nm /\t#$\\",
       },
       "targets": [
         "fake_addr_1:9100",
       ],
     }
   ]
   self.assertEqual(ret, expected)