def setUp(self): super(TempestContextTestCase, self).setUp() self.mock_isfile = mock.patch("os.path.isfile", return_value=True).start() self.cred = fakes.FakeCredential(**CRED) self.deployment = fakes.FakeDeployment(uuid="fake_deployment", admin=self.cred) cfg = { "verifier": mock.Mock(deployment=self.deployment), "verification": { "uuid": "uuid" } } cfg["verifier"].manager.home_dir = "/p/a/t/h" cfg["verifier"].manager.configfile = "/fake/path/to/config" self.context = context.TempestContext(cfg) self.context.conf.add_section("compute") self.context.conf.add_section("orchestration") self.context.conf.add_section("scenario")
def setUp(self): super(TempestContextTestCase, self).setUp() self.mock_isfile = mock.patch("os.path.isfile", return_value=True).start() self.cred = fakes.FakeCredential(**CRED) p_cred = mock.patch(PATH + ".credential.OpenStackCredential", return_value=self.cred) p_cred.start() self.addCleanup(p_cred.stop) self.env = mock.Mock(data={"platforms": {"openstack": { "platform_data": {"admin": {}}}}} ) cfg = {"verifier": mock.Mock(env=self.env), "verification": {"uuid": "uuid"}} cfg["verifier"].manager.home_dir = "/p/a/t/h" cfg["verifier"].manager.configfile = "/fake/path/to/config" self.context = context.TempestContext(cfg) self.context.conf.add_section("compute") self.context.conf.add_section("orchestration") self.context.conf.add_section("scenario")
def test_setup(self, mock_create_dir, mock__create_tempest_roles, mock__configure_option, mock_open): verifier = mock.Mock(deployment=self.deployment) verifier.manager.home_dir = "/p/a/t/h" # case #1: no neutron and heat self.cred.clients.return_value.services.return_value = {} ctx = context.TempestContext({"verifier": verifier}) ctx.conf = mock.Mock() ctx.setup() ctx.conf.read.assert_called_once_with(verifier.manager.configfile) mock_create_dir.assert_called_once_with(ctx.data_dir) mock__create_tempest_roles.assert_called_once_with() mock_open.assert_called_once_with(verifier.manager.configfile, "w") ctx.conf.write(mock_open.side_effect()) self.assertEqual([ mock.call("DEFAULT", "log_file", "/p/a/t/h/tempest.log"), mock.call("oslo_concurrency", "lock_path", "/p/a/t/h/lock_files"), mock.call("scenario", "img_dir", "/p/a/t/h"), mock.call("scenario", "img_file", ctx.image_name, helper_method=ctx._download_image), mock.call("compute", "image_ref", helper_method=ctx._discover_or_create_image), mock.call("compute", "image_ref_alt", helper_method=ctx._discover_or_create_image), mock.call("compute", "flavor_ref", helper_method=ctx._discover_or_create_flavor, flv_ram=config.CONF.openstack.flavor_ref_ram, flv_disk=config.CONF.openstack.flavor_ref_disk), mock.call("compute", "flavor_ref_alt", helper_method=ctx._discover_or_create_flavor, flv_ram=config.CONF.openstack.flavor_ref_alt_ram, flv_disk=config.CONF.openstack.flavor_ref_alt_disk) ], mock__configure_option.call_args_list) mock_create_dir.reset_mock() mock__create_tempest_roles.reset_mock() mock_open.reset_mock() mock__configure_option.reset_mock() # case #2: neutron and heat are presented self.cred.clients.return_value.services.return_value = { "network": "neutron", "orchestration": "heat" } ctx = context.TempestContext({"verifier": verifier}) neutron = ctx.clients.neutron() neutron.list_networks.return_value = {"networks": ["fake_net"]} ctx.conf = mock.Mock() ctx.setup() ctx.conf.read.assert_called_once_with(verifier.manager.configfile) mock_create_dir.assert_called_once_with(ctx.data_dir) mock__create_tempest_roles.assert_called_once_with() mock_open.assert_called_once_with(verifier.manager.configfile, "w") ctx.conf.write(mock_open.side_effect()) self.assertEqual([ mock.call("DEFAULT", "log_file", "/p/a/t/h/tempest.log"), mock.call("oslo_concurrency", "lock_path", "/p/a/t/h/lock_files"), mock.call("scenario", "img_dir", "/p/a/t/h"), mock.call("scenario", "img_file", ctx.image_name, helper_method=ctx._download_image), mock.call("compute", "image_ref", helper_method=ctx._discover_or_create_image), mock.call("compute", "image_ref_alt", helper_method=ctx._discover_or_create_image), mock.call("compute", "flavor_ref", helper_method=ctx._discover_or_create_flavor, flv_ram=config.CONF.openstack.flavor_ref_ram, flv_disk=config.CONF.openstack.flavor_ref_disk), mock.call("compute", "flavor_ref_alt", helper_method=ctx._discover_or_create_flavor, flv_ram=config.CONF.openstack.flavor_ref_alt_ram, flv_disk=config.CONF.openstack.flavor_ref_alt_disk), mock.call("compute", "fixed_network_name", helper_method=ctx._create_network_resources), mock.call("orchestration", "instance_type", helper_method=ctx._discover_or_create_flavor, flv_ram=config.CONF.openstack.heat_instance_type_ram) ], mock__configure_option.call_args_list)