Exemplo n.º 1
0
 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,
             )
Exemplo n.º 2
0
 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,
             )
Exemplo n.º 3
0
 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,
             )
Exemplo n.º 4
0
 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,
             )
Exemplo n.º 5
0
 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,
     )
Exemplo n.º 6
0
 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,
     )
Exemplo n.º 7
0
 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,
         )
Exemplo n.º 8
0
 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,
         )
Exemplo n.º 9
0
 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,
         )
Exemplo n.º 10
0
 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,
         )