def test_create_and_delete_entity(self): action_name = 'action-1' playbook = [{ 'hosts': 'netscaler', 'gather_facts': False, 'tasks': [{ 'name': 'setup lb vserver 1', 'local_action': { 'operation': 'present', 'module': 'netscaler_lb_vserver', 'name': 'lb-vserver-1', 'ipv46': '10.79.1.1', 'port': 80, 'servicetype': 'HTTP', }, }] }] playbook[0]['tasks'][0]['local_action'].update(utils.nitro_dict) # Create lb vserver result = utils.run_ansible_play(playbook, testcase='Create_cs_action_entity') self.assertIsNotNone( result, msg='Result from playbook run did not return valid json') self.assertFalse(result['failed'], msg='Playbook initial returned failed status') self.assertTrue(result['changed'], msg='Changed status was not set correctly') playbook = [{ 'hosts': 'netscaler', 'gather_facts': False, 'tasks': [{ 'name': 'setup monitor', 'local_action': { 'operation': 'present', 'module': 'netscaler_cs_action', 'name': action_name, 'targetlbvserver': 'lb-vserver-1', }, }] }] from nssrc.com.citrix.netscaler.nitro.resource.config.cs.csaction import csaction playbook[0]['tasks'][0]['local_action'].update(utils.nitro_dict) # Create entity result = utils.run_ansible_play(playbook, testcase='Create_cs_action_entity') self.assertIsNotNone( result, msg='Result from playbook run did not return valid json') self.assertFalse(result['failed'], msg='Playbook initial returned failed status') self.assertTrue(result['changed'], msg='Changed status was not set correctly') # Make sure the named entiry exists only once count = csaction.count_filtered(utils.get_nitro_client(), 'name:%s' % action_name) self.assertEqual(count, 1, msg='%s was not deleted properly' % action_name) # Delete entity playbook[0]['tasks'][0]['local_action']['operation'] = 'absent' result = utils.run_ansible_play(playbook, testcase='Delete_cs_action_entity') self.assertIsNotNone( result, msg='Result from playbook run did not return valid json') self.assertFalse(result['failed'], msg='Playbook initial returned failed status') self.assertTrue(result['changed'], msg='Changed status was not set correctly') # Make sure the named entiry does not exist count = csaction.count_filtered(utils.get_nitro_client(), 'name:%s' % action_name) self.assertEqual(count, 0, msg='%s was not deleted properly' % action_name)
def action_exists(client, module): if csaction.count_filtered(client, 'name:%s' % module.params['name']) > 0: return True else: return False