Lazily load the IPAClient objects
This change ensures that the JoinController does not instantiate an IPAClient object each time it is invoked -- every time a compute.update notifcation comes in. Rather it does so only after confirming the notification was meant to create a node that will be enrolled within IPA. Change-Id: I6511d1a4f174e277735e8a68cb711c78193243a9
This commit is contained in:
parent
a71617627a
commit
2fb79eee23
|
@ -77,9 +77,20 @@ class Controller(object):
|
|||
|
||||
class JoinController(Controller):
|
||||
|
||||
def __init__(self, ipaclient=IPAClient()):
|
||||
def __init__(self, ipaclient=None):
|
||||
super(JoinController, self).__init__(None)
|
||||
self.ipaclient = ipaclient
|
||||
|
||||
LOG.debug("hr debug -- ipaclient: %s", ipaclient)
|
||||
self._ipaclient = ipaclient
|
||||
LOG.debug("hr debug -- self.ipaclient: %s", self.ipaclient)
|
||||
|
||||
@property
|
||||
def ipaclient(self):
|
||||
if self._ipaclient is None:
|
||||
LOG.debug("hr testing -- self._ipaclient was None")
|
||||
self._ipaclient = IPAClient()
|
||||
LOG.debug("hr testing -- self._ipaclient is now: %s", self._ipaclient)
|
||||
return self._ipaclient
|
||||
|
||||
def _get_allowed_hostclass(self, project_name):
|
||||
"""Get the allowed list of hostclass from configuration."""
|
||||
|
@ -192,8 +203,8 @@ class JoinController(Controller):
|
|||
ipaotp = uuid.uuid4().hex
|
||||
instance_id = body.get('instance-id', '')
|
||||
|
||||
data['hostname'] = util.get_fqdn(hostname_short, project_name)
|
||||
_, realm = self.ipaclient.get_host_and_realm()
|
||||
data['hostname'] = util.get_fqdn(hostname_short, project_name)
|
||||
data['krb_realm'] = realm
|
||||
|
||||
try:
|
||||
|
|
|
@ -33,6 +33,8 @@ import paramiko
|
|||
from novajoin import config
|
||||
from novajoin.ipa import IPAClient
|
||||
|
||||
import logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
@ -55,11 +57,18 @@ class TestEnrollment(testtools.TestCase):
|
|||
"""
|
||||
|
||||
def setUp(self):
|
||||
LOG.debug("hr testing -- begin test_enrollment.TestEnrollment.setUp")
|
||||
super(TestEnrollment, self).setUp()
|
||||
CONF.keytab = '/tmp/test.keytab'
|
||||
if not os.path.isfile(CONF.keytab):
|
||||
CONF.keytab = '/etc/novajoin/krb5.keytab'
|
||||
self.ipaclient = IPAClient()
|
||||
try:
|
||||
LOG.debug("hr testing -- api hash: %s", str(hash(api)))
|
||||
except Exception as e:
|
||||
LOG.debug("hr testing -- unable to access API object directly in test")
|
||||
LOG.debug("hr testing -- error: %s", e)
|
||||
|
||||
self.conn = openstack.connect(
|
||||
auth_url='http://127.0.0.1/identity', project_name='demo',
|
||||
username='demo', password='secretadmin', region_name='RegionOne',
|
||||
|
@ -82,6 +91,11 @@ class TestEnrollment(testtools.TestCase):
|
|||
network = self.conn.network.find_network('public')
|
||||
self._ip = self.conn.network.create_ip(floating_network_id=network.id)
|
||||
self._server = None
|
||||
try:
|
||||
LOG.debug("hr testing -- api hash2: %s", str(hash(api)))
|
||||
except Exception as e:
|
||||
LOG.debug("hr testing -- unable to access API object directly in test")
|
||||
LOG.debug("hr testing -- error: %s", e)
|
||||
|
||||
def tearDown(self):
|
||||
super(TestEnrollment, self).tearDown()
|
||||
|
@ -92,6 +106,7 @@ class TestEnrollment(testtools.TestCase):
|
|||
self.conn.network.delete_ip(self._ip)
|
||||
|
||||
def _create_server(self):
|
||||
LOG.debug("hr testing -- begin test_enrollment._create_server")
|
||||
image = self.conn.compute.find_image(TEST_IMAGE)
|
||||
flavor = self.conn.compute.find_flavor('m1.small')
|
||||
network = self.conn.network.find_network('private')
|
||||
|
@ -105,6 +120,11 @@ class TestEnrollment(testtools.TestCase):
|
|||
})
|
||||
|
||||
server = self.conn.compute.wait_for_server(self._server)
|
||||
try:
|
||||
LOG.debug("hr testing -- api hash: %s", str(hash(api)))
|
||||
except Exception as e:
|
||||
LOG.debug("hr testing -- unable to access API object directly in test")
|
||||
LOG.debug("hr testing -- error: %s", e)
|
||||
return server
|
||||
|
||||
def _update_server_compact_service_new(self):
|
||||
|
@ -127,6 +147,7 @@ class TestEnrollment(testtools.TestCase):
|
|||
self.assertSetEqual(set(services), set(service_list))
|
||||
|
||||
def _associate_floating_ip(self):
|
||||
LOG.debug("hr testing -- begin test_enrollment._associate_floating_ip")
|
||||
self.conn.compute.add_floating_ip_to_server(
|
||||
self._server, self._ip.floating_ip_address)
|
||||
|
||||
|
@ -156,6 +177,7 @@ class TestEnrollment(testtools.TestCase):
|
|||
return client
|
||||
|
||||
def _check_ipa_client_install(self):
|
||||
LOG.debug("hr testing -- begin test_enrollment._check_ipa_client_install")
|
||||
ssh = self._ssh_connect()
|
||||
tries = 100
|
||||
while tries:
|
||||
|
@ -181,6 +203,14 @@ class TestEnrollment(testtools.TestCase):
|
|||
|
||||
@loopingcall.RetryDecorator(200, 5, 5, (AssertionError,))
|
||||
def _check_ipa_client_created(self):
|
||||
LOG.debug("hr testing -- begin test_enrollment._check_ipa_client_created")
|
||||
LOG.debug("hr testing -- test is breaking here")
|
||||
LOG.debug("hr testing -- test instance: %s, example_domain: %s", TEST_INSTANCE, EXAMPLE_DOMAIN)
|
||||
try:
|
||||
LOG.debug("hr testing -- api hash: %s", str(hash(api)))
|
||||
except Exception as e:
|
||||
LOG.debug("hr testing -- unable to access API object directly in test")
|
||||
LOG.debug("hr testing -- error: %s", e)
|
||||
self.assertTrue(
|
||||
self.ipaclient.find_host(TEST_INSTANCE + EXAMPLE_DOMAIN))
|
||||
|
||||
|
@ -200,11 +230,16 @@ class TestEnrollment(testtools.TestCase):
|
|||
self.ipaclient.find_record(self._ip.floating_ip_address))
|
||||
|
||||
def test_enroll_server(self):
|
||||
self._create_server()
|
||||
LOG.debug("hr testing -- begin test_enrollment.test_enroll_server")
|
||||
testing_server = self._create_server()
|
||||
LOG.debug("hr testing -- test_enroll_server.server: %s", testing_server)
|
||||
LOG.debug("hr testing -- test_enroll_server.server hash: %s", str(hash(testing_server)))
|
||||
|
||||
self._associate_floating_ip()
|
||||
|
||||
self._check_ipa_client_install()
|
||||
|
||||
# FIXME(hryabcki) check client created is breaking
|
||||
self._check_ipa_client_created()
|
||||
self._check_ip_record_added()
|
||||
self._disassociate_floating_ip()
|
||||
|
|
Loading…
Reference in New Issue