def test_configmap_present__replace(self): cm = self.make_configmap(name='settings', data={'action': 'make=war'}) # Replace an existing configmap with self.mock_func('show_configmap', return_value=cm): new_cm = cm.copy() new_cm.update({ 'data': { 'action': 'make=peace' }, }) with self.mock_func('replace_configmap', return_value=new_cm): actual = kubernetes.configmap_present( name='settings', data={'action': 'make=peace'}, ) self.assertDictEqual( { 'comment': 'The configmap is already present. Forcing recreation', 'changes': { 'data': { 'action': 'make=peace', }, }, 'name': 'settings', 'result': True, }, actual, )
def test_configmap_present__create(self): # Create a new configmap with self.mock_func('show_configmap', return_value=None): cm = self.make_configmap( name='test', namespace='default', data={'foo': 'bar'}, ) with self.mock_func('create_configmap', return_value=cm): actual = kubernetes.configmap_present( name='test', data={'foo': 'bar'}, ) self.assertDictEqual( { 'comment': '', 'changes': { 'data': { 'foo': 'bar' } }, 'name': 'test', 'result': True, }, actual, )
def test_configmap_present__replace(self): cm = self.make_configmap(name="settings", data={"action": "make=war"}) # Replace an existing configmap with self.mock_func("show_configmap", return_value=cm): new_cm = cm.copy() new_cm.update({"data": {"action": "make=peace"}}) with self.mock_func("replace_configmap", return_value=new_cm): actual = kubernetes.configmap_present( name="settings", data={"action": "make=peace"}, ) self.assertDictEqual( { "comment": ("The configmap is already present. Forcing recreation" ), "changes": { "data": { "action": "make=peace" } }, "name": "settings", "result": True, }, actual, )
def test_configmap_present__create(self): # Create a new configmap with self.mock_func("show_configmap", return_value=None): cm = self.make_configmap( name="test", namespace="default", data={"foo": "bar"}, ) with self.mock_func("create_configmap", return_value=cm): actual = kubernetes.configmap_present( name="test", data={"foo": "bar"}, ) self.assertDictEqual( { "comment": "", "changes": { "data": { "foo": "bar" } }, "name": "test", "result": True, }, actual, )
def test_configmap_present__fail(self): error = kubernetes.configmap_present( name="testme", data={1: 1}, source="salt://beyond/oblivion.jinja", ) self.assertDictEqual( { "changes": {}, "result": False, "name": "testme", "comment": "'source' cannot be used in combination with 'data'", }, error, )
def test_configmap_present__fail(self): error = kubernetes.configmap_present( name='testme', data={1: 1}, source='salt://beyond/oblivion.jinja', ) self.assertDictEqual( { 'changes': {}, 'result': False, 'name': 'testme', 'comment': "'source' cannot be used in combination with 'data'", }, error, )
def test_configmap_present__create_test_true(self): # Create a new configmap with test=True with self.mock_func("show_configmap", return_value=None, test=True): ret = kubernetes.configmap_present( name="example", data={"example.conf": "# empty config file"}, ) self.assertDictEqual( { "comment": "The configmap is going to be created", "changes": {}, "name": "example", "result": None, }, ret, )
def test_configmap_present__create_test_true(self): # Create a new configmap with test=True with self.mock_func('show_configmap', return_value=None, test=True): ret = kubernetes.configmap_present( name='example', data={'example.conf': '# empty config file'}, ) self.assertDictEqual( { 'comment': 'The configmap is going to be created', 'changes': {}, 'name': 'example', 'result': None, }, ret, )
def test_configmap_present__replace_test_true(self): cm = self.make_configmap( name='settings', namespace='saltstack', data={'foobar.conf': '# Example configuration'}, ) with self.mock_func('show_configmap', return_value=cm, test=True): ret = kubernetes.configmap_present( name='settings', namespace='saltstack', data={'foobar.conf': '# Example configuration'}, ) self.assertDictEqual( { 'comment': 'The configmap is going to be replaced', 'changes': {}, 'name': 'settings', 'result': None, }, ret, )
def test_configmap_present__replace_test_true(self): cm = self.make_configmap( name="settings", namespace="saltstack", data={"foobar.conf": "# Example configuration"}, ) with self.mock_func("show_configmap", return_value=cm, test=True): ret = kubernetes.configmap_present( name="settings", namespace="saltstack", data={"foobar.conf": "# Example configuration"}, ) self.assertDictEqual( { "comment": "The configmap is going to be replaced", "changes": {}, "name": "settings", "result": None, }, ret, )