def test_endpoint_present(self): ''' Test to ensure the specified endpoints exists for service ''' name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} endpoint = { 'adminurl': None, 'region': 'RegionOne', 'internalurl': None, 'publicurl': None, 'id': 1, 'service_id': None } mock_lst = MagicMock(side_effect=[ endpoint, ['Error'], { 'id': 1, 'service_id': None }, [] ]) mock = MagicMock(return_value=True) with patch.dict(keystone.__salt__, { 'keystone.endpoint_get': mock_lst, 'keystone.endpoint_create': mock }): comt = ('endpoint for service "{0}" already exists'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {'test': True}): comt = ( 'Endpoint for service "{0}" will be added'.format(name)) ret.update({ 'comment': comt, 'result': None, 'changes': { 'endpoint': 'Will be created' } }) self.assertDictEqual(keystone.endpoint_present(name), ret) comt = ( 'Endpoint for service "{0}" will be updated'.format(name)) ret.update({ 'comment': comt, 'changes': { 'endpoint': 'Will be updated' } }) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {'test': False}): comt = ( 'Endpoint for service "{0}" has been added'.format(name)) ret.update({'comment': comt, 'result': True, 'changes': True}) self.assertDictEqual(keystone.endpoint_present(name), ret)
def test_endpoint_present(self): """ Test to ensure the specified endpoints exists for service """ name = "nova" region = "RegionOne" ret = {"name": name, "changes": {}, "result": True, "comment": ""} endpoint = { "adminurl": None, "region": None, "internalurl": None, "publicurl": None, "id": 1, "service_id": None, } mock_lst = MagicMock( side_effect=[endpoint, ["Error"], {"id": 1, "service_id": None}, []] ) mock = MagicMock(return_value=True) with patch.dict( keystone.__salt__, {"keystone.endpoint_get": mock_lst, "keystone.endpoint_create": mock}, ): comt = 'Endpoint for service "{}" already exists'.format(name) ret.update({"comment": comt, "result": True, "changes": {}}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {"test": True}): comt = 'Endpoint for service "{}" will be added'.format(name) ret.update( { "comment": comt, "result": None, "changes": {"Endpoint": "Will be created"}, } ) self.assertDictEqual(keystone.endpoint_present(name), ret) comt = 'Endpoint for service "{}" already exists'.format(name) ret.update({"comment": comt, "result": True, "changes": {}}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {"test": False}): comt = 'Endpoint for service "{}" has been added'.format(name) ret.update({"comment": comt, "result": True, "changes": True}) self.assertDictEqual(keystone.endpoint_present(name), ret)
def test_endpoint_present(self): ''' Test to ensure the specified endpoints exists for service ''' name = 'nova' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} endpoint = {'adminurl': None, 'region': 'RegionOne', 'internalurl': None, 'publicurl': None, 'id': 1, 'service_id': None} mock_lst = MagicMock(side_effect=[endpoint, ['Error'], {'id': 1, 'service_id': None}, []]) mock = MagicMock(return_value=True) with patch.dict(keystone.__salt__, {'keystone.endpoint_get': mock_lst, 'keystone.endpoint_create': mock}): comt = ('Endpoint for service "{0}" already exists'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {'test': True}): comt = ('Endpoint for service "{0}" will be added'.format(name)) ret.update({'comment': comt, 'result': None, 'changes': {'Endpoint': 'Will be created'}}) self.assertDictEqual(keystone.endpoint_present(name), ret) comt = ('Endpoint for service "{0}" will be updated' .format(name)) ret.update({'comment': comt, 'changes': {'Endpoint': 'Will be updated'}}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {'test': False}): comt = ('Endpoint for service "{0}" has been added' .format(name)) ret.update({'comment': comt, 'result': True, 'changes': True}) self.assertDictEqual(keystone.endpoint_present(name), ret)
def test_endpoint_present(self): """ Test to ensure the specified endpoints exists for service """ name = "nova" ret = {"name": name, "changes": {}, "result": True, "comment": ""} endpoint = { "adminurl": None, "region": "RegionOne", "internalurl": None, "publicurl": None, "id": 1, "service_id": None, } mock_lst = MagicMock(side_effect=[endpoint, ["Error"], {"id": 1, "service_id": None}, []]) mock = MagicMock(return_value=True) with patch.dict(keystone.__salt__, {"keystone.endpoint_get": mock_lst, "keystone.endpoint_create": mock}): comt = 'endpoint for service "{0}" already exists'.format(name) ret.update({"comment": comt}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {"test": True}): comt = 'Endpoint for service "{0}" will be added'.format(name) ret.update({"comment": comt, "result": None, "changes": {"endpoint": "Will be created"}}) self.assertDictEqual(keystone.endpoint_present(name), ret) comt = 'Endpoint for service "{0}" will be updated'.format(name) ret.update({"comment": comt, "changes": {"endpoint": "Will be updated"}}) self.assertDictEqual(keystone.endpoint_present(name), ret) with patch.dict(keystone.__opts__, {"test": False}): comt = 'Endpoint for service "{0}" has been added'.format(name) ret.update({"comment": comt, "result": True, "changes": True}) self.assertDictEqual(keystone.endpoint_present(name), ret)