Exemplo n.º 1
0
def servicegroup_exists(client, module):
    log('Checking if service group exists')
    count = servicegroup.count_filtered(client, 'servicegroupname:%s' % module.params['servicegroupname'])
    log('count is %s' % count)
    if count > 0:
        return True
    else:
        return False
 def service_group_exists():
     log('service_group_exists')
     if servicegroup.count_filtered(
             client,
             'servicegroupname:%s' % module.params['servicegroupname']) > 0:
         return True
     else:
         return False
    def test_create_and_delete_entity(self):
        servicegroup_name = 'servicegroup-1'
        playbook = [{
            'hosts':
            'netscaler',
            'gather_facts':
            False,
            'tasks': [{
                'name': 'setup monitor',
                'local_action': {
                    'operation':
                    'present',
                    'module':
                    'netscaler_servicegroup',
                    'servicegroupname':
                    servicegroup_name,
                    'servicetype':
                    'HTTP',
                    'cachetype':
                    'TRANSPARENT',
                    'maxclient':
                    100,
                    'servicemembers': [
                        {
                            'ip': '10.78.78.78',
                            'port': 80,
                            'weight': 60,
                        },
                        {
                            'ip': '10.79.79.79',
                            'port': 80,
                            'weight': 40,
                        },
                    ],
                },
            }]
        }]

        from nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup import servicegroup
        playbook[0]['tasks'][0]['local_action'].update(utils.nitro_dict)
        # Create entity
        result = utils.run_ansible_play(playbook,
                                        testcase='Create_servicegroup_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 = servicegroup.count_filtered(utils.get_nitro_client(),
                                            'name:%s' % servicegroup_name)
        self.assertEqual(count,
                         1,
                         msg='%s was not deleted properly' % servicegroup_name)

        # Delete entity
        playbook[0]['tasks'][0]['local_action']['operation'] = 'absent'
        result = utils.run_ansible_play(playbook,
                                        testcase='Delete_servicegroup_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 = servicegroup.count_filtered(utils.get_nitro_client(),
                                            'name:%s' % servicegroup_name)
        self.assertEqual(count,
                         0,
                         msg='%s was not deleted properly' % servicegroup_name)