Browse Source

Enhance the basic enrollment test

This additionaly logs into the server instance and
checks the IPA client configuration.

Change-Id: Ic249032e9241f13c843119f798efbe598a62c88e
Grzegorz Grasza 5 months ago
parent
commit
62475be1c2
1 changed files with 43 additions and 2 deletions
  1. 43
    2
      novajoin/tests/functional/test_enrollment.py

+ 43
- 2
novajoin/tests/functional/test_enrollment.py View File

@@ -19,12 +19,16 @@ The test uses the default demo project and credentials and assumes there is a
19 19
 centos-image present in Glance.
20 20
 """
21 21
 
22
+import json
22 23
 import os
24
+import StringIO
23 25
 import testtools
26
+import time
24 27
 import uuid
25 28
 
26 29
 import openstack
27 30
 from oslo_service import loopingcall
31
+import paramiko
28 32
 
29 33
 from novajoin import config
30 34
 from novajoin.ipa import IPAClient
@@ -64,13 +68,14 @@ class TestEnrollment(testtools.TestCase):
64 68
         self._key = self.conn.compute.create_keypair(name=TEST_KEY)
65 69
         group = self.conn.network.find_security_group('default')
66 70
         self._rules = []
67
-        for protocol, port in [('icmp', None), ('tcp', 22), ('tcp', 443)]:
71
+        for protocol in ['icmp', 'tcp', 'udp']:
68 72
             try:
69 73
                 self._rules.append(
70 74
                     self.conn.network.create_security_group_rule(
71 75
                         security_group_id=group.id, direction='ingress',
72 76
                         remote_ip_prefix='0.0.0.0/0', protocol=protocol,
73
-                        port_range_max=port, port_range_min=port,
77
+                        port_range_min=(protocol == 'icmp' and 0 or 1),
78
+                        port_range_max=(protocol == 'icmp' and 255 or 65535),
74 79
                         ethertype='IPv4'))
75 80
             except openstack.exceptions.ConflictException:
76 81
                 pass
@@ -112,6 +117,39 @@ class TestEnrollment(testtools.TestCase):
112 117
             self.conn.compute.delete_server(self._server)
113 118
         self._server = None
114 119
 
120
+    @loopingcall.RetryDecorator(50, 5, 5, (
121
+        paramiko.ssh_exception.NoValidConnectionsError,))
122
+    def _ssh_connect(self):
123
+        # NOTE(xek): We are connectiong to the floating IP address.
124
+        # Alternatively we could connect to self._server.access_ipv4, but then
125
+        # we wouldn't be able to connect to keystone from the same namespace.
126
+
127
+        pkey = paramiko.RSAKey.from_private_key(
128
+            StringIO.StringIO(self._key.private_key))
129
+        client = paramiko.SSHClient()
130
+        client.load_system_host_keys()
131
+        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
132
+        client.connect(self._ip.floating_ip_address,
133
+                       username=TEST_IMAGE_USER, pkey=pkey)
134
+        return client
135
+
136
+    def _check_ipa_client_install(self):
137
+        ssh = self._ssh_connect()
138
+        tries = 100
139
+        while tries:
140
+            stdin, stdout, stderr = ssh.exec_command(
141
+                'cat /run/cloud-init/status.json')
142
+            data = json.load(stdout)
143
+            if data.get("v1", {}).get("datasource"):
144
+                time.sleep(5)
145
+                tries -= 1
146
+            else:  # cloud-init script finished
147
+                break
148
+        stdin, stdout, stderr = ssh.exec_command('id admin')
149
+        self.assertRegex(
150
+            'uid=\d+\(admin\) gid=\d+\(admins\) groups=\d+\(admins\)',
151
+            stdout.read())
152
+
115 153
     @loopingcall.RetryDecorator(200, 5, 5, (AssertionError,))
116 154
     def _check_ipa_client_created(self):
117 155
         self.assertTrue(
@@ -141,6 +179,9 @@ class TestEnrollment(testtools.TestCase):
141 179
         self._check_ip_record_removed()
142 180
         self._associate_floating_ip()
143 181
         self._check_ip_record_added()
182
+
183
+        self._check_ipa_client_install()
184
+
144 185
         self._delete_server()
145 186
         self._check_ipa_client_deleted()
146 187
         self._check_ip_record_removed()

Loading…
Cancel
Save