def _create_elasticsearch_rule(self):
        from system_tests.openstack_handler import OpenstackHandler
        os_handler = OpenstackHandler(self.env)
        neutron_client = os_handler.openstack_clients()[1]
        sgr = {
            'direction': 'ingress',
            'ethertype': 'IPv4',
            'port_range_max': str(ELASTICSEARCH_PORT),
            'port_range_min': str(ELASTICSEARCH_PORT),
            'protocol': 'tcp',
            'remote_group_id': None,
            'remote_ip_prefix': '0.0.0.0/0',
        }

        mng_sec_grp_name = self.env.management_security_group

        mng_sec_grp = neutron_client. \
            list_security_groups(name=mng_sec_grp_name)['security_groups'][0]

        sg_id = mng_sec_grp['id']
        sgr['security_group_id'] = sg_id
        try:
            self.elasticsearch_rule = neutron_client. \
                create_security_group_rule(
                    {'security_group_rule': sgr})['security_group_rule']['id']
            if not util.wait_for_open_port(self.env.management_ip,
                                           ELASTICSEARCH_PORT, 60):
                raise Exception('Could not open elasticsearch port')

        except NeutronClientException as e:
            self.elasticsearch_rule = None
            self.logger.warning("Got NeutronClientException({0}). Resuming"
                                .format(e))
    def _create_elasticsearch_rule(self):
        from system_tests.openstack_handler import OpenstackHandler
        os_handler = OpenstackHandler(self.env)
        neutron_client = os_handler.openstack_clients()[1]
        sgr = {
            'direction': 'ingress',
            'ethertype': 'IPv4',
            'port_range_max': str(ELASTICSEARCH_PORT),
            'port_range_min': str(ELASTICSEARCH_PORT),
            'protocol': 'tcp',
            'remote_group_id': None,
            'remote_ip_prefix': '0.0.0.0/0',
        }

        mng_sec_grp_name = self.env.management_security_group

        mng_sec_grp = neutron_client. \
            list_security_groups(name=mng_sec_grp_name)['security_groups'][0]

        sg_id = mng_sec_grp['id']
        sgr['security_group_id'] = sg_id
        try:
            self.elasticsearch_rule = neutron_client. \
                create_security_group_rule(
                    {'security_group_rule': sgr})['security_group_rule']['id']
            if not util.wait_for_open_port(self.env.management_ip,
                                           ELASTICSEARCH_PORT, 60):
                raise Exception('Could not open elasticsearch port')

        except NeutronClientException as e:
            self.elasticsearch_rule = None
            self.logger.warning("Got NeutronClientException({0}). Resuming"
                                .format(e))
 def _delete_elasticsearch_rule(self):
     if self.elasticsearch_rule is not None:
         from system_tests.openstack_handler import OpenstackHandler
         os_handler = OpenstackHandler(self.env)
         neutron_client = os_handler.openstack_clients()[1]
         neutron_client.delete_security_group_rule(self.elasticsearch_rule)
 def _delete_elasticsearch_rule(self):
     if self.elasticsearch_rule is not None:
         from system_tests.openstack_handler import OpenstackHandler
         os_handler = OpenstackHandler(self.env)
         neutron_client = os_handler.openstack_clients()[1]
         neutron_client.delete_security_group_rule(self.elasticsearch_rule)