From 2cb0e674f3e5ace44b1b1e8ffc5c19a6af2166be Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Wed, 18 Mar 2015 20:09:44 +0800 Subject: [PATCH] Switch config deferred_auth_method to trusts by default Change deferred_auth_method to trusts by default, and fixes unittests error. Closes-Bug: #1286157 Change-Id: Ifebbc1b5d71458d8502e08bcacbd94b7437128f9 --- .../extraroute/tests/test_extraroute.py | 1 - .../tests/test_rackspace_cloud_server.py | 1 - heat/common/config.py | 2 +- .../autoscaling/test_heat_scaling_group.py | 5 ---- .../autoscaling/test_heat_scaling_policy.py | 3 --- heat/tests/autoscaling/test_launch_config.py | 1 - heat/tests/autoscaling/test_scaling_group.py | 4 --- heat/tests/autoscaling/test_scaling_policy.py | 3 --- heat/tests/aws/test_waitcondition.py | 3 --- heat/tests/common.py | 5 ++-- heat/tests/fakes.py | 14 ++++++++-- heat/tests/openstack/test_waitcondition.py | 1 - heat/tests/test_ceilometer_alarm.py | 1 - heat/tests/test_clients.py | 9 +++++++ heat/tests/test_eip.py | 1 - heat/tests/test_engine_service.py | 10 ++++--- heat/tests/test_metadata_refresh.py | 3 --- heat/tests/test_network_interface.py | 1 - heat/tests/test_neutron.py | 6 ----- heat/tests/test_neutron_firewall.py | 3 --- heat/tests/test_neutron_loadbalancer.py | 5 ---- heat/tests/test_neutron_metering.py | 2 -- heat/tests/test_neutron_network_gateway.py | 1 - heat/tests/test_neutron_security_group.py | 1 - heat/tests/test_neutron_vpnservice.py | 4 --- heat/tests/test_nova_floatingip.py | 1 - heat/tests/test_os_database.py | 1 - heat/tests/test_s3.py | 1 - heat/tests/test_security_group.py | 1 - heat/tests/test_server.py | 1 - heat/tests/test_signal.py | 4 +-- heat/tests/test_stack.py | 9 +------ heat/tests/test_stack_delete.py | 26 +++---------------- heat/tests/test_vpc.py | 1 - 34 files changed, 39 insertions(+), 96 deletions(-) diff --git a/contrib/extraroute/extraroute/tests/test_extraroute.py b/contrib/extraroute/extraroute/tests/test_extraroute.py index 013e488b63..721edca136 100644 --- a/contrib/extraroute/extraroute/tests/test_extraroute.py +++ b/contrib/extraroute/extraroute/tests/test_extraroute.py @@ -57,7 +57,6 @@ class NeutronExtraRouteTest(common.HeatTestCase): super(NeutronExtraRouteTest, self).setUp() self.m.StubOutWithMock(neutronclient.Client, 'show_router') self.m.StubOutWithMock(neutronclient.Client, 'update_router') - self.stub_keystoneclient() resource._register_class("OS::Neutron::ExtraRoute", extraroute.ExtraRoute) diff --git a/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py b/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py index 9d158f486b..72842e5b81 100644 --- a/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py +++ b/contrib/rackspace/rackspace/tests/test_rackspace_cloud_server.py @@ -71,7 +71,6 @@ class CloudServersTest(common.HeatTestCase): 'nova')._create = mock_nova_create mock_nova_create.return_value = self.fc - self.stub_keystoneclient() # Test environment may not have pyrax client library installed and if # pyrax is not installed resource class would not be registered. # So register resource provider class explicitly for unit testing. diff --git a/heat/common/config.py b/heat/common/config.py index 80e756c3dd..0173b4b92c 100644 --- a/heat/common/config.py +++ b/heat/common/config.py @@ -99,7 +99,7 @@ engine_opts = [ help=_('The directory to search for environment files.')), cfg.StrOpt('deferred_auth_method', choices=['password', 'trusts'], - default='password', + default='trusts', help=_('Select deferred auth method, ' 'stored password or trusts.')), cfg.ListOpt('trusts_delegated_roles', diff --git a/heat/tests/autoscaling/test_heat_scaling_group.py b/heat/tests/autoscaling/test_heat_scaling_group.py index 640371f813..17f6cb1fbe 100644 --- a/heat/tests/autoscaling/test_heat_scaling_group.py +++ b/heat/tests/autoscaling/test_heat_scaling_group.py @@ -35,7 +35,6 @@ class TestAutoScalingGroupValidation(common.HeatTestCase): generic_resource.ResourceWithPropsAndAttrs) cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() self.parsed = template_format.parse(inline_templates.as_heat_template) def test_invalid_min_size(self): @@ -96,7 +95,6 @@ class TestInitialGroupSize(common.HeatTestCase): super(TestInitialGroupSize, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def test_initial_size(self): t = template_format.parse(inline_templates.as_heat_template) @@ -118,7 +116,6 @@ class TestGroupAdjust(common.HeatTestCase): 'http://server.test:8000/v1/waitcondition') resource._register_class('ResourceWithPropsAndAttrs', generic_resource.ResourceWithPropsAndAttrs) - self.stub_keystoneclient() t = template_format.parse(inline_templates.as_heat_template) stack = utils.parse_stack(t, params=inline_templates.as_params) @@ -230,7 +227,6 @@ class TestGroupCrud(common.HeatTestCase): generic_resource.ResourceWithPropsAndAttrs) cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() self.stub_ImageConstraint_validate() self.stub_FlavorConstraint_validate() self.stub_SnapshotConstraint_validate() @@ -312,7 +308,6 @@ class HeatScalingGroupAttrTest(common.HeatTestCase): 'http://server.test:8000/v1/waitcondition') resource._register_class('ResourceWithPropsAndAttrs', generic_resource.ResourceWithPropsAndAttrs) - self.stub_keystoneclient() t = template_format.parse(inline_templates.as_heat_template) stack = utils.parse_stack(t, params=inline_templates.as_params) diff --git a/heat/tests/autoscaling/test_heat_scaling_policy.py b/heat/tests/autoscaling/test_heat_scaling_policy.py index 0eda1d1c18..8ba9db5152 100644 --- a/heat/tests/autoscaling/test_heat_scaling_policy.py +++ b/heat/tests/autoscaling/test_heat_scaling_policy.py @@ -35,7 +35,6 @@ class TestAutoScalingPolicy(common.HeatTestCase): super(TestAutoScalingPolicy, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_scaling_policy(self, t, stack, resource_name): rsrc = stack[resource_name] @@ -101,7 +100,6 @@ class TestCooldownMixin(common.HeatTestCase): super(TestCooldownMixin, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_scaling_policy(self, t, stack, resource_name): rsrc = stack[resource_name] @@ -177,7 +175,6 @@ class TestCooldownMixin(common.HeatTestCase): class ScalingPolicyAttrTest(common.HeatTestCase): def setUp(self): super(ScalingPolicyAttrTest, self).setUp() - self.stub_keystoneclient() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') t = template_format.parse(as_template) diff --git a/heat/tests/autoscaling/test_launch_config.py b/heat/tests/autoscaling/test_launch_config.py index 591427bc0c..57f4b4778d 100644 --- a/heat/tests/autoscaling/test_launch_config.py +++ b/heat/tests/autoscaling/test_launch_config.py @@ -30,7 +30,6 @@ class LaunchConfigurationTest(common.HeatTestCase): super(LaunchConfigurationTest, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def validate_launch_config(self, t, stack, resource_name): # create the launch configuration resource diff --git a/heat/tests/autoscaling/test_scaling_group.py b/heat/tests/autoscaling/test_scaling_group.py index 89217cd8a2..b1e2d72ffd 100644 --- a/heat/tests/autoscaling/test_scaling_group.py +++ b/heat/tests/autoscaling/test_scaling_group.py @@ -38,7 +38,6 @@ class TestAutoScalingGroupValidation(common.HeatTestCase): super(TestAutoScalingGroupValidation, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def validate_scaling_group(self, t, stack, resource_name): # create the launch configuration resource @@ -277,7 +276,6 @@ class TestInitialGroupSize(common.HeatTestCase): super(TestInitialGroupSize, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def test_initial_size(self): t = template_format.parse(as_template) @@ -297,7 +295,6 @@ class TestGroupAdjust(common.HeatTestCase): super(TestGroupAdjust, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() t = template_format.parse(as_template) stack = utils.parse_stack(t, params=inline_templates.as_params) @@ -407,7 +404,6 @@ class TestGroupCrud(common.HeatTestCase): super(TestGroupCrud, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() t = template_format.parse(as_template) stack = utils.parse_stack(t, params=inline_templates.as_params) diff --git a/heat/tests/autoscaling/test_scaling_policy.py b/heat/tests/autoscaling/test_scaling_policy.py index 09aabea0c6..4a529ab16c 100644 --- a/heat/tests/autoscaling/test_scaling_policy.py +++ b/heat/tests/autoscaling/test_scaling_policy.py @@ -35,7 +35,6 @@ class TestAutoScalingPolicy(common.HeatTestCase): super(TestAutoScalingPolicy, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_scaling_policy(self, t, stack, resource_name): rsrc = stack[resource_name] @@ -102,7 +101,6 @@ class TestCooldownMixin(common.HeatTestCase): super(TestCooldownMixin, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_scaling_policy(self, t, stack, resource_name): rsrc = stack[resource_name] @@ -178,7 +176,6 @@ class TestCooldownMixin(common.HeatTestCase): class ScalingPolicyAttrTest(common.HeatTestCase): def setUp(self): super(ScalingPolicyAttrTest, self).setUp() - self.stub_keystoneclient() t = template_format.parse(as_template) stack = utils.parse_stack(t, params=as_params) self.policy = stack['WebServerScaleUpPolicy'] diff --git a/heat/tests/aws/test_waitcondition.py b/heat/tests/aws/test_waitcondition.py index f5de1ea2e7..e76484bab7 100644 --- a/heat/tests/aws/test_waitcondition.py +++ b/heat/tests/aws/test_waitcondition.py @@ -80,7 +80,6 @@ class WaitConditionTest(common.HeatTestCase): super(WaitConditionTest, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_stack(self, stack_id=None, template=test_template_waitcondition, params=None, @@ -353,7 +352,6 @@ class WaitConditionHandleTest(common.HeatTestCase): super(WaitConditionHandleTest, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_stack(self, stack_name=None, stack_id=None): temp = template_format.parse(test_template_waitcondition) @@ -524,7 +522,6 @@ class WaitConditionUpdateTest(common.HeatTestCase): super(WaitConditionUpdateTest, self).setUp() cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() def create_stack(self, tmpl=None): if tmpl is None: diff --git a/heat/tests/common.py b/heat/tests/common.py index 592808b0c9..0b158f7cce 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -72,7 +72,7 @@ class HeatTestCase(testscenarios.WithScenarios, TIME_STEP = 0.1 - def setUp(self): + def setUp(self, mock_keystone=True): super(HeatTestCase, self).setUp() self.m = mox.Mox() self.addCleanup(self.m.UnsetStubs) @@ -112,7 +112,8 @@ class HeatTestCase(testscenarios.WithScenarios, # use CWLiteAlarm for testing. resources.global_env().registry.load( {"AWS::CloudWatch::Alarm": "OS::Heat::CWLiteAlarm"}) - + if mock_keystone: + self.stub_keystoneclient() utils.setup_dummy_db() self.addCleanup(utils.reset_dummy_db) diff --git a/heat/tests/fakes.py b/heat/tests/fakes.py index e7707db16c..04e6d4718b 100644 --- a/heat/tests/fakes.py +++ b/heat/tests/fakes.py @@ -96,9 +96,10 @@ class FakeAuth(auth.BaseAuthPlugin): class FakeKeystoneClient(object): - def __init__(self, username='test_user', password='apassword', + def __init__(self, username='test_username', password='password', user_id='1234', access='4567', secret='8901', - credential_id='abcdxyz'): + credential_id='abcdxyz', auth_token='abcd1234', + context=None): self.username = username self.password = password self.user_id = user_id @@ -106,6 +107,8 @@ class FakeKeystoneClient(object): self.secret = secret self.session = session.Session() self.credential_id = credential_id + self.token = auth_token + self.context = context class FakeCred(object): id = self.credential_id @@ -183,3 +186,10 @@ class FakeKeystoneClient(object): def stack_domain_user_token(self, user_id, project_id, password): return 'adomainusertoken' + + @property + def auth_token(self): + if self.context is not None: + return self.context.auth_plugin.get_token(self.session) + else: + return self.token \ No newline at end of file diff --git a/heat/tests/openstack/test_waitcondition.py b/heat/tests/openstack/test_waitcondition.py index 5698711b93..d0eb35dcd7 100644 --- a/heat/tests/openstack/test_waitcondition.py +++ b/heat/tests/openstack/test_waitcondition.py @@ -72,7 +72,6 @@ class HeatWaitConditionTest(common.HeatTestCase): def setUp(self): super(HeatWaitConditionTest, self).setUp() - self.stub_keystoneclient() self.tenant_id = 'test_tenant' def create_stack(self, stack_id=None, diff --git a/heat/tests/test_ceilometer_alarm.py b/heat/tests/test_ceilometer_alarm.py index f8b114fc75..fa1c4fba03 100644 --- a/heat/tests/test_ceilometer_alarm.py +++ b/heat/tests/test_ceilometer_alarm.py @@ -121,7 +121,6 @@ class CeilometerAlarmTest(common.HeatTestCase): cfg.CONF.set_default('heat_waitcondition_server_url', 'http://server.test:8000/v1/waitcondition') - self.stub_keystoneclient() self.fa = mock.Mock() def create_stack(self, template=None): diff --git a/heat/tests/test_clients.py b/heat/tests/test_clients.py index 498027ed5e..aa0c449b35 100644 --- a/heat/tests/test_clients.py +++ b/heat/tests/test_clients.py @@ -95,6 +95,7 @@ class ClientsTest(common.HeatTestCase): con.tenant_id = "b363706f891f48019483f8bd6503c54b" con.auth_token = None con.auth_plugin = fakes.FakeAuth(auth_token='anewtoken') + self.stub_keystoneclient(context=con) c = clients.Clients(con) con.clients = c @@ -200,6 +201,13 @@ class ClientPluginTest(common.HeatTestCase): @mock.patch.object(context, "RequestContext") @mock.patch.object(v3, "Token", name="v3_token") def test_get_missing_service_catalog(self, mock_v3, mkreqctx): + class FakeKeystone(fakes.FakeKeystoneClient): + def __init__(self): + super(FakeKeystone, self).__init__() + self.client = self + self.version = 'v3' + + self.stub_keystoneclient(fake_client=FakeKeystone()) con = mock.Mock(auth_token="1234", trust_id=None) c = clients.Clients(con) con.clients = c @@ -213,6 +221,7 @@ class ClientPluginTest(common.HeatTestCase): mock_token_obj = mock.Mock() mock_token_obj.get_auth_ref.return_value = {'catalog': 'foo'} mock_v3.return_value = mock_token_obj + plugin = FooClientsPlugin(con) mock_cxt_dict = {'auth_token_info': {'token': {'catalog': 'baz'}}} plugin.context.to_dict.return_value = mock_cxt_dict diff --git a/heat/tests/test_eip.py b/heat/tests/test_eip.py index d9b7b310cb..da463786ec 100644 --- a/heat/tests/test_eip.py +++ b/heat/tests/test_eip.py @@ -391,7 +391,6 @@ class AllocTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'list_routers') self.m.StubOutWithMock(neutronclient.Client, 'remove_gateway_router') - self.stub_keystoneclient() def _setup_test_stack(self, stack_name): t = template_format.parse(ipassoc_template_validate) diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index fcaa78e456..eee5a99702 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -211,7 +211,8 @@ def setup_mock_for_image_constraint(mocks, imageId_input, imageId_input).MultipleTimes().AndReturn(imageId_output) -def setup_mocks(mocks, stack, mock_image_constraint=True): +def setup_mocks(mocks, stack, mock_image_constraint=True, + mock_keystone=True): fc = fakes_v1_1.FakeClient() mocks.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().MultipleTimes().AndReturn(fc) @@ -223,7 +224,8 @@ def setup_mocks(mocks, stack, mock_image_constraint=True): setup_mock_for_image_constraint(mocks, instance.t['Properties']['ImageId']) - setup_keystone_mocks(mocks, stack) + if mock_keystone: + setup_keystone_mocks(mocks, stack) user_data = instance.properties['UserData'] server_userdata = instance.client_plugin().build_userdata( @@ -415,7 +417,7 @@ class StackCreateTest(common.HeatTestCase): def test_wordpress_single_instance_stack_delete(self): ctx = utils.dummy_context() stack = get_wordpress_stack('test_stack', ctx) - fc = setup_mocks(self.m, stack) + fc = setup_mocks(self.m, stack, mock_keystone=False) self.m.ReplayAll() stack_id = stack.store() stack.create() @@ -669,6 +671,7 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase): stack.t.t, {}, None, {}) def test_stack_create_no_credentials(self): + cfg.CONF.set_default('deferred_auth_method', 'password') stack_name = 'test_stack_create_no_credentials' params = {'foo': 'bar'} template = '{ "Template": "data" }' @@ -1351,6 +1354,7 @@ class StackServiceCreateUpdateDeleteTest(common.HeatTestCase): self.m.VerifyAll() def test_stack_update_no_credentials(self): + cfg.CONF.set_default('deferred_auth_method', 'password') stack_name = 'test_stack_update_no_credentials' params = {'foo': 'bar'} template = '{ "Template": "data" }' diff --git a/heat/tests/test_metadata_refresh.py b/heat/tests/test_metadata_refresh.py index c279455790..38b929785f 100644 --- a/heat/tests/test_metadata_refresh.py +++ b/heat/tests/test_metadata_refresh.py @@ -149,7 +149,6 @@ class MetadataRefreshTest(common.HeatTestCase): ''' def setUp(self): super(MetadataRefreshTest, self).setUp() - self.stub_keystoneclient() def create_stack(self, stack_name='test_stack', params=None): params = params or {} @@ -211,7 +210,6 @@ class MetadataRefreshTest(common.HeatTestCase): class WaitCondMetadataUpdateTest(common.HeatTestCase): def setUp(self): super(WaitCondMetadataUpdateTest, self).setUp() - self.stub_keystoneclient() self.patch('heat.engine.service.warnings') self.man = service.EngineService('a-host', 'a-topic') @@ -309,7 +307,6 @@ class MetadataRefreshTestServer(common.HeatTestCase): ''' def setUp(self): super(MetadataRefreshTestServer, self).setUp() - self.stub_keystoneclient() def create_stack(self, stack_name='test_stack_native', params=None): params = params or {} diff --git a/heat/tests/test_network_interface.py b/heat/tests/test_network_interface.py index 0cfe9dfb19..7953c476e8 100644 --- a/heat/tests/test_network_interface.py +++ b/heat/tests/test_network_interface.py @@ -44,7 +44,6 @@ class NetworkInterfaceTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'create_port') self.m.StubOutWithMock(neutronclient.Client, 'delete_port') self.m.StubOutWithMock(neutronclient.Client, 'update_port') - self.stub_keystoneclient() def mock_show_subnet(self): neutronclient.Client.show_subnet('ssss').AndReturn({ diff --git a/heat/tests/test_neutron.py b/heat/tests/test_neutron.py index 64cd88afb3..8b6ae78c44 100644 --- a/heat/tests/test_neutron.py +++ b/heat/tests/test_neutron.py @@ -725,7 +725,6 @@ class NeutronNetTest(common.HeatTestCase): 'remove_network_from_dhcp_agent') self.m.StubOutWithMock(neutronclient.Client, 'list_dhcp_agent_hosting_networks') - self.stub_keystoneclient() def create_net(self, t, stack, resource_name): resource_defns = stack.t.resource_definitions(stack) @@ -918,7 +917,6 @@ class NeutronProviderNetTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'show_network') self.m.StubOutWithMock(neutronclient.Client, 'delete_network') self.m.StubOutWithMock(neutronclient.Client, 'update_network') - self.stub_keystoneclient() def create_provider_net(self): # Create script @@ -1037,7 +1035,6 @@ class NeutronSubnetTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'show_subnet') self.m.StubOutWithMock(neutronclient.Client, 'update_subnet') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') - self.stub_keystoneclient() def create_subnet(self, t, stack, resource_name): resource_defns = stack.t.resource_definitions(stack) @@ -1436,7 +1433,6 @@ class NeutronRouterTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'list_l3_agent_hosting_routers') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') - self.stub_keystoneclient() def create_router(self, t, stack, resource_name): resource_defns = stack.t.resource_definitions(stack) @@ -2197,7 +2193,6 @@ class NeutronFloatingIPTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'show_port') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') - self.stub_keystoneclient() def test_floating_ip_router_interface(self): t = template_format.parse(neutron_floating_template) @@ -2704,7 +2699,6 @@ class NeutronPortTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'update_port') self.m.StubOutWithMock(neutronclient.Client, 'show_subnet') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') - self.stub_keystoneclient() def test_missing_subnet_id(self): neutronV20.find_resourceid_by_name_or_id( diff --git a/heat/tests/test_neutron_firewall.py b/heat/tests/test_neutron_firewall.py index eba814d100..7722b7f7fe 100644 --- a/heat/tests/test_neutron_firewall.py +++ b/heat/tests/test_neutron_firewall.py @@ -93,7 +93,6 @@ class FirewallTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_firewall') self.m.StubOutWithMock(neutronclient.Client, 'show_firewall') self.m.StubOutWithMock(neutronclient.Client, 'update_firewall') - self.stub_keystoneclient() def create_firewall(self): neutronclient.Client.create_firewall({ @@ -222,7 +221,6 @@ class FirewallPolicyTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_firewall_policy') self.m.StubOutWithMock(neutronclient.Client, 'show_firewall_policy') self.m.StubOutWithMock(neutronclient.Client, 'update_firewall_policy') - self.stub_keystoneclient() def create_firewall_policy(self): neutronclient.Client.create_firewall_policy({ @@ -348,7 +346,6 @@ class FirewallRuleTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_firewall_rule') self.m.StubOutWithMock(neutronclient.Client, 'show_firewall_rule') self.m.StubOutWithMock(neutronclient.Client, 'update_firewall_rule') - self.stub_keystoneclient() def create_firewall_rule(self): neutronclient.Client.create_firewall_rule({ diff --git a/heat/tests/test_neutron_loadbalancer.py b/heat/tests/test_neutron_loadbalancer.py index 4804a03b4f..6fc1953671 100644 --- a/heat/tests/test_neutron_loadbalancer.py +++ b/heat/tests/test_neutron_loadbalancer.py @@ -229,7 +229,6 @@ class HealthMonitorTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_health_monitor') self.m.StubOutWithMock(neutronclient.Client, 'show_health_monitor') self.m.StubOutWithMock(neutronclient.Client, 'update_health_monitor') - self.stub_keystoneclient() def create_health_monitor(self): neutronclient.Client.create_health_monitor({ @@ -362,7 +361,6 @@ class PoolTest(common.HeatTestCase): self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') self.m.StubOutWithMock(neutronclient.Client, 'delete_vip') self.m.StubOutWithMock(neutronclient.Client, 'show_vip') - self.stub_keystoneclient() def create_pool(self, resolve_neutron=True, with_vip_subnet=False): neutronclient.Client.create_pool({ @@ -854,7 +852,6 @@ class PoolMemberTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_member') self.m.StubOutWithMock(neutronclient.Client, 'update_member') self.m.StubOutWithMock(neutronclient.Client, 'show_member') - self.stub_keystoneclient() def create_member(self): neutronclient.Client.create_member({ @@ -954,7 +951,6 @@ class LoadBalancerTest(common.HeatTestCase): self.fc = fakes_v1_1.FakeClient() self.m.StubOutWithMock(neutronclient.Client, 'create_member') self.m.StubOutWithMock(neutronclient.Client, 'delete_member') - self.stub_keystoneclient() self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') def create_load_balancer(self): @@ -1052,7 +1048,6 @@ class PoolUpdateHealthMonitorsTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'create_vip') self.m.StubOutWithMock(neutronclient.Client, 'delete_vip') self.m.StubOutWithMock(neutronclient.Client, 'show_vip') - self.stub_keystoneclient() def _create_pool_with_health_monitors(self): neutronclient.Client.create_health_monitor({ diff --git a/heat/tests/test_neutron_metering.py b/heat/tests/test_neutron_metering.py index 62a8d8d6a0..9fcd02b112 100644 --- a/heat/tests/test_neutron_metering.py +++ b/heat/tests/test_neutron_metering.py @@ -64,7 +64,6 @@ class MeteringLabelTest(common.HeatTestCase): 'delete_metering_label_rule') self.m.StubOutWithMock(neutronclient.Client, 'show_metering_label_rule') - self.stub_keystoneclient() def create_metering_label(self): neutronclient.Client.create_metering_label({ @@ -177,7 +176,6 @@ class MeteringRuleTest(common.HeatTestCase): 'delete_metering_label_rule') self.m.StubOutWithMock(neutronclient.Client, 'show_metering_label_rule') - self.stub_keystoneclient() def create_metering_label_rule(self): neutronclient.Client.create_metering_label_rule({ diff --git a/heat/tests/test_neutron_network_gateway.py b/heat/tests/test_neutron_network_gateway.py index 4540100856..01046f06c0 100644 --- a/heat/tests/test_neutron_network_gateway.py +++ b/heat/tests/test_neutron_network_gateway.py @@ -104,7 +104,6 @@ class NeutronNetworkGatewayTest(common.HeatTestCase): 'disconnect_network_gateway') self.m.StubOutWithMock(neutronclient.Client, 'list_networks') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') - self.stub_keystoneclient() def mock_create_fail_network_not_found_delete_success(self): neutronclient.Client.create_network_gateway({ diff --git a/heat/tests/test_neutron_security_group.py b/heat/tests/test_neutron_security_group.py index 607de5010b..bf3772ea4a 100644 --- a/heat/tests/test_neutron_security_group.py +++ b/heat/tests/test_neutron_security_group.py @@ -86,7 +86,6 @@ Resources: def setUp(self): super(SecurityGroupTest, self).setUp() self.fc = fakes_v1_1.FakeClient() - self.stub_keystoneclient() self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'delete') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'create') diff --git a/heat/tests/test_neutron_vpnservice.py b/heat/tests/test_neutron_vpnservice.py index a06b523787..bbc99ec7ca 100644 --- a/heat/tests/test_neutron_vpnservice.py +++ b/heat/tests/test_neutron_vpnservice.py @@ -171,7 +171,6 @@ class VPNServiceTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'show_vpnservice') self.m.StubOutWithMock(neutronclient.Client, 'update_vpnservice') self.m.StubOutWithMock(neutronV20, 'find_resourceid_by_name_or_id') - self.stub_keystoneclient() def create_vpnservice(self, resolve_neutron=True, resolve_router=True): self.stub_SubnetConstraint_validate() @@ -350,7 +349,6 @@ class IPsecSiteConnectionTest(common.HeatTestCase): 'show_ipsec_site_connection') self.m.StubOutWithMock(neutronclient.Client, 'update_ipsec_site_connection') - self.stub_keystoneclient() def create_ipsec_site_connection(self): neutronclient.Client.create_ipsec_site_connection( @@ -497,7 +495,6 @@ class IKEPolicyTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_ikepolicy') self.m.StubOutWithMock(neutronclient.Client, 'show_ikepolicy') self.m.StubOutWithMock(neutronclient.Client, 'update_ikepolicy') - self.stub_keystoneclient() def create_ikepolicy(self): neutronclient.Client.create_ikepolicy( @@ -638,7 +635,6 @@ class IPsecPolicyTest(common.HeatTestCase): self.m.StubOutWithMock(neutronclient.Client, 'delete_ipsecpolicy') self.m.StubOutWithMock(neutronclient.Client, 'show_ipsecpolicy') self.m.StubOutWithMock(neutronclient.Client, 'update_ipsecpolicy') - self.stub_keystoneclient() def create_ipsecpolicy(self): neutronclient.Client.create_ipsecpolicy( diff --git a/heat/tests/test_nova_floatingip.py b/heat/tests/test_nova_floatingip.py index 11579c4332..54c7260e82 100644 --- a/heat/tests/test_nova_floatingip.py +++ b/heat/tests/test_nova_floatingip.py @@ -69,7 +69,6 @@ class NovaFloatingIPTest(common.HeatTestCase): self.m.StubOutWithMock(self.novaclient.servers, 'get') self.m.StubOutWithMock(self.novaclient.servers, 'add_floating_ip') self.m.StubOutWithMock(self.novaclient.servers, 'remove_floating_ip') - self.stub_keystoneclient() nova.NovaClientPlugin.get_server = mock.Mock( return_value=mock.MagicMock()) diff --git a/heat/tests/test_os_database.py b/heat/tests/test_os_database.py index a6152477d9..31e2df6def 100644 --- a/heat/tests/test_os_database.py +++ b/heat/tests/test_os_database.py @@ -98,7 +98,6 @@ class FakeVersion(object): class OSDBInstanceTest(common.HeatTestCase): def setUp(self): super(OSDBInstanceTest, self).setUp() - self.stub_keystoneclient() self.fc = self.m.CreateMockAnything() self.nova = self.m.CreateMockAnything() self.m.StubOutWithMock(trove.TroveClientPlugin, '_create') diff --git a/heat/tests/test_s3.py b/heat/tests/test_s3.py index 59cdb45a3d..0e36b8ed02 100644 --- a/heat/tests/test_s3.py +++ b/heat/tests/test_s3.py @@ -70,7 +70,6 @@ class s3Test(common.HeatTestCase): self.m.StubOutWithMock(sc.Connection, 'get_container') self.m.StubOutWithMock(sc.Connection, 'delete_container') self.m.StubOutWithMock(sc.Connection, 'get_auth') - self.stub_keystoneclient() def create_resource(self, t, stack, resource_name): resource_defns = stack.t.resource_definitions(stack) diff --git a/heat/tests/test_security_group.py b/heat/tests/test_security_group.py index e89d051fa0..572552443f 100644 --- a/heat/tests/test_security_group.py +++ b/heat/tests/test_security_group.py @@ -132,7 +132,6 @@ Resources: super(SecurityGroupTest, self).setUp() self.fc = fakes_v1_1.FakeClient() self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') - self.stub_keystoneclient() self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'create') self.m.StubOutWithMock(nova_sgr.SecurityGroupRuleManager, 'delete') self.m.StubOutWithMock(nova_sg.SecurityGroupManager, 'create') diff --git a/heat/tests/test_server.py b/heat/tests/test_server.py index ee3abaf4b8..e7b6a783b1 100644 --- a/heat/tests/test_server.py +++ b/heat/tests/test_server.py @@ -99,7 +99,6 @@ class ServersTest(common.HeatTestCase): def setUp(self): super(ServersTest, self).setUp() self.fc = fakes_v1_1.FakeClient() - self.stub_keystoneclient() self.limits = self.m.CreateMockAnything() self.limits.absolute = self._limits_absolute() diff --git a/heat/tests/test_signal.py b/heat/tests/test_signal.py index 3ba8b9d673..1d42d17a30 100644 --- a/heat/tests/test_signal.py +++ b/heat/tests/test_signal.py @@ -94,12 +94,12 @@ class SignalTest(common.HeatTestCase): self.m.VerifyAll() def test_resource_data(self): - self.stack = self.create_stack(stack_name='resource_data_test', - stub=False) self.stub_keystoneclient( access='anaccesskey', secret='verysecret', credential_id='mycredential') + self.stack = self.create_stack(stack_name='resource_data_test', + stub=False) self.m.ReplayAll() self.stack.create() diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index 34f21ad72e..39cc44bbad 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -501,13 +501,6 @@ class StackTest(common.HeatTestCase): self.stack.state) def test_abandon_nodelete_project(self): - fkc = fakes.FakeKeystoneClient() - fkc.delete_stack_domain_project = mock.Mock() - - self.m.StubOutWithMock(keystone.KeystoneClientPlugin, '_create') - keystone.KeystoneClientPlugin._create().AndReturn(fkc) - self.m.ReplayAll() - self.stack = stack.Stack(self.ctx, 'delete_trust', self.tmpl) stack_id = self.stack.store() @@ -522,7 +515,6 @@ class StackTest(common.HeatTestCase): self.assertIsNone(db_s) self.assertEqual((stack.Stack.DELETE, stack.Stack.COMPLETE), self.stack.state) - self.assertFalse(fkc.delete_stack_domain_project.called) def test_suspend_resume(self): self.m.ReplayAll() @@ -1107,6 +1099,7 @@ class StackTest(common.HeatTestCase): """ A user_creds entry is created on first stack store """ + cfg.CONF.set_default('deferred_auth_method', 'password') self.stack = stack.Stack(self.ctx, 'creds_stack', self.tmpl) self.stack.store() diff --git a/heat/tests/test_stack_delete.py b/heat/tests/test_stack_delete.py index de3191120c..1cb84707a0 100644 --- a/heat/tests/test_stack_delete.py +++ b/heat/tests/test_stack_delete.py @@ -16,7 +16,6 @@ import time from keystoneclient import exceptions as kc_exceptions import mock -from oslo_config import cfg from heat.common import exception from heat.common import heat_keystoneclient as hkc @@ -137,7 +136,6 @@ class StackTest(common.HeatTestCase): self.stack.state) def test_delete_trust(self): - cfg.CONF.set_override('deferred_auth_method', 'trusts') self.stub_keystoneclient() self.stack = stack.Stack(self.ctx, 'delete_trust', self.tmpl) @@ -154,17 +152,12 @@ class StackTest(common.HeatTestCase): self.stack.state) def test_delete_trust_trustor(self): - cfg.CONF.set_override('deferred_auth_method', 'trusts') - + self.stub_keystoneclient(user_id='thetrustor') trustor_ctx = utils.dummy_context(user_id='thetrustor') - mock_kc = self.patchobject(hkc, 'KeystoneClient') - mock_kc.return_value = fakes.FakeKeystoneClient(user_id='thetrustor') self.stack = stack.Stack(trustor_ctx, 'delete_trust_nt', self.tmpl) stack_id = self.stack.store() - mock_kc.assert_called_once_with(trustor_ctx) - db_s = db_api.stack_get(self.ctx, stack_id) self.assertIsNotNone(db_s) @@ -181,8 +174,6 @@ class StackTest(common.HeatTestCase): self.stack.state) def test_delete_trust_not_trustor(self): - cfg.CONF.set_override('deferred_auth_method', 'trusts') - # Stack gets created with trustor_ctx, deleted with other_ctx # then the trust delete should be with stored_ctx trustor_ctx = utils.dummy_context(user_id='thetrustor') @@ -190,14 +181,13 @@ class StackTest(common.HeatTestCase): stored_ctx = utils.dummy_context(trust_id='thetrust') mock_kc = self.patchobject(hkc, 'KeystoneClient') - mock_kc.return_value = fakes.FakeKeystoneClient(user_id='thetrustor') + self.stub_keystoneclient(user_id='thetrustor') mock_sc = self.patchobject(stack.Stack, 'stored_context') mock_sc.return_value = stored_ctx self.stack = stack.Stack(trustor_ctx, 'delete_trust_nt', self.tmpl) stack_id = self.stack.store() - mock_kc.assert_called_once_with(trustor_ctx) db_s = db_api.stack_get(self.ctx, stack_id) self.assertIsNotNone(db_s) @@ -212,8 +202,6 @@ class StackTest(common.HeatTestCase): loaded_stack = stack.Stack.load(other_ctx, self.stack.id) loaded_stack.delete() mock_sc.assert_called_with() - mock_kc.assert_has_calls([mock.call(trustor_ctx), - mock.call(stored_ctx)]) db_s = db_api.stack_get(other_ctx, stack_id) self.assertIsNone(db_s) @@ -221,8 +209,6 @@ class StackTest(common.HeatTestCase): loaded_stack.state) def test_delete_trust_backup(self): - cfg.CONF.set_override('deferred_auth_method', 'trusts') - class FakeKeystoneClientFail(fakes.FakeKeystoneClient): def delete_trust(self, trust_id): raise Exception("Shouldn't delete") @@ -245,8 +231,6 @@ class StackTest(common.HeatTestCase): mock_kcp.assert_called_once_with() def test_delete_trust_nested(self): - cfg.CONF.set_override('deferred_auth_method', 'trusts') - class FakeKeystoneClientFail(fakes.FakeKeystoneClient): def delete_trust(self, trust_id): raise Exception("Shouldn't delete") @@ -274,8 +258,6 @@ class StackTest(common.HeatTestCase): self.stack.state) def test_delete_trust_fail(self): - cfg.CONF.set_override('deferred_auth_method', 'trusts') - class FakeKeystoneClientFail(fakes.FakeKeystoneClient): def delete_trust(self, trust_id): raise kc_exceptions.Forbidden("Denied!") @@ -317,7 +299,7 @@ class StackTest(common.HeatTestCase): self.stack.delete() - mock_kcp.assert_called_once_with() + mock_kcp.assert_called_with() db_s = db_api.stack_get(self.ctx, stack_id) self.assertIsNone(db_s) @@ -429,7 +411,7 @@ class StackTest(common.HeatTestCase): self.stack.delete() - mock_kcp.assert_called_once_with() + mock_kcp.assert_called_with() self.assertEqual((stack.Stack.DELETE, stack.Stack.FAILED), self.stack.state) self.assertIn('Error deleting project', self.stack.status_reason) diff --git a/heat/tests/test_vpc.py b/heat/tests/test_vpc.py index 90e6980a4a..f946e6815e 100644 --- a/heat/tests/test_vpc.py +++ b/heat/tests/test_vpc.py @@ -59,7 +59,6 @@ class VPCTestBase(common.HeatTestCase): neutronclient.Client, 'create_security_group_rule') self.m.StubOutWithMock( neutronclient.Client, 'delete_security_group_rule') - self.stub_keystoneclient() def create_stack(self, templ): t = template_format.parse(templ)