def test_configlet_action_add_with_task(self, mock_template):
     ''' Test configlet_action add with change updates configlet and adds
         proper info to return data. Including task spawned info.
     '''
     module = Mock()
     module.params = dict(action='add', switch_name='eos', switch_port='3')
     config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     configlet = dict(name='eos-server', key='key', config=config)
     template_config = ('interface Ethernet3\n   description Host eos'
                        ' managed by Ansible and Jinja template\n'
                        '   load-interval 30\n'
                        '   switchport\n'
                        '   switchport mode trunk\n'
                        '   no shutdown\n!')
     mock_template.return_value = template_config
     update_return = dict(data='Configlet eos-server successfully updated'
                          ' and task initiated.')
     module.client.api.update_configlet.return_value = update_return
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['oldConfigBlock'], 'interface Ethernet3\n!')
     full_config = '!\n' + template_config + '\ninterface Ethernet4\n!'
     self.assertEqual(result['fullConfig'], full_config)
     self.assertEqual(result['updateConfigletResponse'],
                      update_return['data'])
     self.assertTrue(result['changed'])
     self.assertTrue(result['taskCreated'])
     self.assertEqual(module.client.api.update_configlet.call_count, 1)
 def test_configlet_action_remove_with_task(self):
     ''' Test configlet_action remove with change updates configlet and adds
         proper info to return data. Including task spawned info.
     '''
     module = Mock()
     module.params = dict(action='remove',
                          switch_name='eos',
                          switch_port='3')
     config = ('!\ninterface Ethernet3\n   description test\n'
               '!\ninterface Ethernet4\n!')
     configlet = dict(name='eos-server', key='key', config=config)
     update_return = dict(data='Configlet eos-server successfully updated'
                          ' and task initiated.')
     module.client.api.update_configlet.return_value = update_return
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['oldConfigBlock'],
                      'interface Ethernet3\n   description test\n!')
     full_config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     self.assertEqual(result['fullConfig'], full_config)
     self.assertEqual(result['updateConfigletResponse'],
                      update_return['data'])
     self.assertTrue(result['changed'])
     self.assertTrue(result['taskCreated'])
     self.assertEqual(module.client.api.update_configlet.call_count, 1)
 def test_configlet_action_add_with_task(self, mock_template):
     ''' Test configlet_action add with change updates configlet and adds
         proper info to return data. Including task spawned info.
     '''
     module = Mock()
     module.params = dict(action='add', switch_name='eos', switch_port='3')
     config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     configlet = dict(name='eos-server', key='key', config=config)
     template_config = ('interface Ethernet3\n   description Host eos'
                        ' managed by Ansible and Jinja template\n'
                        '   load-interval 30\n'
                        '   switchport\n'
                        '   switchport mode trunk\n'
                        '   no shutdown\n!')
     mock_template.return_value = template_config
     update_return = dict(data='Configlet eos-server successfully updated'
                               ' and task initiated.')
     module.client.api.update_configlet.return_value = update_return
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['oldConfigBlock'], 'interface Ethernet3\n!')
     full_config = '!\n' + template_config + '\ninterface Ethernet4\n!'
     self.assertEqual(result['fullConfig'], full_config)
     self.assertEqual(result['updateConfigletResponse'],
                      update_return['data'])
     self.assertTrue(result['changed'])
     self.assertTrue(result['taskCreated'])
     self.assertEqual(module.client.api.update_configlet.call_count, 1)
 def test_configlet_action_show_blank_config(self):
     ''' Test configlet_action show returns current port configuration.
     '''
     module = Mock()
     module.params = dict(action='show', switch_name='eos', switch_port='3')
     config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     configlet = dict(name='eos-server', key='key', config=config)
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['currentConfigBlock'], 'interface Ethernet3\n!')
     module.client.api.update_configlet.assert_not_called()
 def test_configlet_action_show_blank_config(self):
     ''' Test configlet_action show returns current port configuration.
     '''
     module = Mock()
     module.params = dict(action='show', switch_name='eos', switch_port='3')
     config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     configlet = dict(name='eos-server', key='key', config=config)
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['currentConfigBlock'],
                      'interface Ethernet3\n!')
     module.client.api.update_configlet.assert_not_called()
 def test_configlet_action_remove_no_task(self):
     ''' Test configlet_action with remove that doesn't change configlet and
         adds proper info to return data. Does not including any task info.
     '''
     module = Mock()
     module.params = dict(action='remove', switch_name='eos',
                          switch_port='3')
     config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     configlet = dict(name='eos-server', key='key', config=config)
     update_return = dict(data='Configlet eos-server successfully updated.')
     module.client.api.update_configlet.return_value = update_return
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['oldConfigBlock'], 'interface Ethernet3\n!')
     self.assertEqual(result['fullConfig'], config)
     self.assertEqual(result['updateConfigletResponse'],
                      update_return['data'])
     self.assertNotIn('changed', result)
     self.assertNotIn('taskCreated', result)
     self.assertEqual(module.client.api.update_configlet.call_count, 1)
 def test_configlet_action_remove_no_task(self):
     ''' Test configlet_action with remove that doesn't change configlet and
         adds proper info to return data. Does not including any task info.
     '''
     module = Mock()
     module.params = dict(action='remove',
                          switch_name='eos',
                          switch_port='3')
     config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     configlet = dict(name='eos-server', key='key', config=config)
     update_return = dict(data='Configlet eos-server successfully updated.')
     module.client.api.update_configlet.return_value = update_return
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['oldConfigBlock'], 'interface Ethernet3\n!')
     self.assertEqual(result['fullConfig'], config)
     self.assertEqual(result['updateConfigletResponse'],
                      update_return['data'])
     self.assertNotIn('changed', result)
     self.assertNotIn('taskCreated', result)
     self.assertEqual(module.client.api.update_configlet.call_count, 1)
 def test_configlet_action_remove_with_task(self):
     ''' Test configlet_action remove with change updates configlet and adds
         proper info to return data. Including task spawned info.
     '''
     module = Mock()
     module.params = dict(action='remove', switch_name='eos',
                          switch_port='3')
     config = ('!\ninterface Ethernet3\n   description test\n'
               '!\ninterface Ethernet4\n!')
     configlet = dict(name='eos-server', key='key', config=config)
     update_return = dict(data='Configlet eos-server successfully updated'
                               ' and task initiated.')
     module.client.api.update_configlet.return_value = update_return
     result = cv_server_provision.configlet_action(module, configlet)
     self.assertIsNotNone(result)
     self.assertEqual(result['oldConfigBlock'],
                      'interface Ethernet3\n   description test\n!')
     full_config = '!\ninterface Ethernet3\n!\ninterface Ethernet4\n!'
     self.assertEqual(result['fullConfig'], full_config)
     self.assertEqual(result['updateConfigletResponse'],
                      update_return['data'])
     self.assertTrue(result['changed'])
     self.assertTrue(result['taskCreated'])
     self.assertEqual(module.client.api.update_configlet.call_count, 1)