Browse Source

Merge "Devops client for fuelweb"

Jenkins 2 years ago
parent
commit
eb0b1fdc2b

+ 37
- 36
fuelweb_test/models/environment.py View File

@@ -21,7 +21,6 @@ from devops.helpers.helpers import tcp_ping_
21 21
 from devops.helpers.helpers import wait_pass
22 22
 from devops.helpers.helpers import wait
23 23
 from devops.helpers.metaclasses import SingletonMeta
24
-from devops.models import Environment
25 24
 from keystoneauth1 import exceptions
26 25
 from proboscis.asserts import assert_equal
27 26
 from proboscis.asserts import assert_true
@@ -104,7 +103,7 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
104 103
     @logwrap
105 104
     def add_syslog_server(self, cluster_id, port=5514):
106 105
         self.fuel_web.add_syslog_server(
107
-            cluster_id, self.d_env.router(), port)
106
+            cluster_id, self.d_env.get_default_gw(), port)
108 107
 
109 108
     def bootstrap_nodes(self, devops_nodes, timeout=settings.BOOTSTRAP_TIMEOUT,
110 109
                         skip_timesync=False):
@@ -147,8 +146,8 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
147 146
         logger.info("Please wait while time on nodes: {0} "
148 147
                     "will be synchronized"
149 148
                     .format(', '.join(sorted(nodes_names))))
150
-        denv = DevopsClient().get_env(self.d_env.name)
151
-        new_time = denv.sync_time(node_names=nodes_names, skip_sync=skip_sync)
149
+        new_time = self.d_env.sync_time(node_names=nodes_names,
150
+                                        skip_sync=skip_sync)
152 151
         for name in sorted(new_time):
153 152
             logger.info("New time on '{0}' = {1}".format(name, new_time[name]))
154 153
 
@@ -169,7 +168,7 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
169 168
             'iface': iface_alias('eth0'),
170 169
             'ip': node.get_ip_address_by_network_name('admin'),
171 170
             'mask': self.d_env.get_network(name='admin').ip.netmask,
172
-            'gw': self.d_env.router(),
171
+            'gw': self.d_env.get_default_gw(),
173 172
             'hostname': ''.join((settings.FUEL_MASTER_HOSTNAME,
174 173
                                  settings.DNS_SUFFIX)),
175 174
             'nat_interface': '',
@@ -229,20 +228,21 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
229 228
             from devops.error import DevopsObjNotFound
230 229
             EnvDoesNotExist = DevopsObjNotFound
231 230
         except ImportError:
231
+            from devops.models import Environment
232 232
             # pylint: disable=no-member
233 233
             EnvDoesNotExist = Environment.DoesNotExist
234 234
             # pylint: enable=no-member
235 235
 
236 236
         try:
237 237
             logger.info("Try to find environment '{0}'".format(env_name))
238
-            self._virt_env = Environment.get(name=env_name)
238
+            self._virt_env = DevopsClient().get_env(env_name)
239 239
         except EnvDoesNotExist:
240 240
             logger.info("Try to create environment '{0}'".format(env_name))
241 241
             if self._config:
242
-                self._virt_env = Environment.create_environment(
243
-                    full_config=self._config)
242
+                self._virt_env = DevopsClient().create_env_from_config(
243
+                    config=self._config)
244 244
             else:
245
-                self._virt_env = Environment.describe_environment(
245
+                self._virt_env = DevopsClient().create_env(
246 246
                     boot_from=settings.ADMIN_BOOT_DEVICE)
247 247
             self._virt_env.define()
248 248
             logger.info("New environment '{0}' was defined".format(env_name))
@@ -348,9 +348,9 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
348 348
         new_login = settings.SSH_FUEL_CREDENTIALS['login']
349 349
         new_password = settings.SSH_FUEL_CREDENTIALS['password']
350 350
         try:
351
-            self.ssh_manager.execute_on_remote(
351
+            self.ssh_manager.check_call(
352 352
                 ip=self.ssh_manager.admin_ip,
353
-                cmd='date'
353
+                command='date'
354 354
             )
355 355
             logger.debug('Accessing admin node using SSH: SUCCESS')
356 356
         except Exception:
@@ -363,10 +363,10 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
363 363
                 slave_login=settings.SSH_SLAVE_CREDENTIALS['login'],
364 364
                 slave_password=settings.SSH_SLAVE_CREDENTIALS['password']
365 365
             )
366
-            self.ssh_manager.execute_on_remote(
366
+            self.ssh_manager.check_call(
367 367
                 ip=self.ssh_manager.admin_ip,
368
-                cmd='echo -e "{1}\\n{1}" | passwd {0}'.format(new_login,
369
-                                                              new_password)
368
+                command='echo -e "{1}\\n{1}" | passwd {0}'.format(new_login,
369
+                                                                  new_password)
370 370
             )
371 371
             self.ssh_manager.initialize(
372 372
                 admin_ip=self.ssh_manager.admin_ip,
@@ -389,14 +389,15 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
389 389
             self.fuel_web.client.get_releases()
390 390
         # TODO(akostrikov) CENTOS7 except exceptions.Unauthorized:
391 391
         except:
392
-            self.ssh_manager.execute_on_remote(
392
+            self.ssh_manager.check_call(
393 393
                 ip=self.ssh_manager.admin_ip,
394
-                cmd='fuel user --newpass {0} --change-password'.format(
395
-                    settings.KEYSTONE_CREDS['password'])
394
+                command='fuel user --newpass {0} --change-password'.format(
395
+                        settings.KEYSTONE_CREDS['password'])
396 396
             )
397
-            config_file = self.ssh_manager.execute_on_remote(
397
+            config_file_path = 'ls -1 $HOME/.config/fuel/fuel_client.yaml'
398
+            config_file = self.ssh_manager.check_call(
398 399
                 ip=self.ssh_manager.admin_ip,
399
-                cmd='ls -1 $HOME/.config/fuel/fuel_client.yaml')['stdout_str']
400
+                command=config_file_path)['stdout_str']
400 401
 
401 402
             with YamlEditor(config_file, ip=self.admin_node_ip) as editor:
402 403
                 editor.content["OS_USERNAME"] = \
@@ -458,7 +459,7 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
458 459
             nessus_node.start()
459 460
         # wait while installation complete
460 461
 
461
-        self.admin_actions.modify_configs(self.d_env.router())
462
+        self.admin_actions.modify_configs(self.d_env.get_default_gw())
462 463
         if CUSTOM_FUEL_SETTING_YAML:
463 464
             self.admin_actions.update_fuel_setting_yaml(
464 465
                 CUSTOM_FUEL_SETTING_YAML)
@@ -471,19 +472,19 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
471 472
         cmd = """
472 473
         echo -e '"SSL":\n  "force_https": "true"' >> /etc/fuel/astute.yaml
473 474
         """
474
-        self.ssh_manager.execute_on_remote(admin_node_ip, cmd)
475
+        self.ssh_manager.check_call(admin_node_ip, cmd)
475 476
         cmd = "find / -name \"nginx_services.pp\""
476 477
         puppet_manifest = \
477
-            self.ssh_manager.execute_on_remote(
478
+            self.ssh_manager.check_call(
478 479
                 admin_node_ip, cmd)['stdout'][0].strip()
479 480
         cmd = 'puppet apply {0}'.format(puppet_manifest)
480
-        self.ssh_manager.execute_on_remote(admin_node_ip, cmd)
481
+        self.ssh_manager.check_call(admin_node_ip, cmd)
481 482
         cmd = """
482 483
         systemctl status nginx.service |
483 484
         awk 'match($0, /\s+Active:.*\((\w+)\)/, a) {print a[1]}'
484 485
         """
485 486
         wait(lambda: (
486
-             self.ssh_manager.execute_on_remote(
487
+             self.ssh_manager.check_call(
487 488
                  admin_node_ip, cmd)['stdout'][0] != 'dead'), interval=10,
488 489
              timeout=30,
489 490
              timeout_msg='Nginx service is dead after trying to enable '
@@ -550,13 +551,13 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
550 551
     def kill_wait_for_external_config(self):
551 552
         kill_cmd = 'pkill -f "^wait_for_external_config"'
552 553
         check_cmd = 'pkill -0 -f "^wait_for_external_config"; [[ $? -eq 1 ]]'
553
-        self.ssh_manager.execute_on_remote(
554
+        self.ssh_manager.check_call(
554 555
             ip=self.ssh_manager.admin_ip,
555
-            cmd=kill_cmd
556
+            command=kill_cmd
556 557
         )
557
-        self.ssh_manager.execute_on_remote(
558
+        self.ssh_manager.check_call(
558 559
             ip=self.ssh_manager.admin_ip,
559
-            cmd=check_cmd
560
+            command=check_cmd
560 561
         )
561 562
 
562 563
     def wait_bootstrap(self):
@@ -606,9 +607,9 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
606 607
                            'is not based on Ubuntu!')
607 608
             return
608 609
 
609
-        bootstrap_images = self.ssh_manager.execute_on_remote(
610
+        bootstrap_images = self.ssh_manager.check_call(
610 611
             ip=self.ssh_manager.admin_ip,
611
-            cmd='fuel-bootstrap --quiet list'
612
+            command='fuel-bootstrap --quiet list'
612 613
         )['stdout']
613 614
         assert_true(any('active' in line for line in bootstrap_images),
614 615
                     'Ubuntu bootstrap image wasn\'t built and activated! '
@@ -662,10 +663,10 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
662 663
                          'yum update -y 2>>/var/log/yum-update-error.log'
663 664
 
664 665
         logger.info('Performing yum clean and update commands')
665
-        update_result = self.ssh_manager.execute_on_remote(
666
+        update_result = self.ssh_manager.check_call(
666 667
             ip=self.ssh_manager.admin_ip,
667
-            cmd=update_command,
668
-            err_msg='Packages update failed, inspect logs for details')
668
+            command=update_command,
669
+            error_info='Packages update failed, inspect logs for details')
669 670
 
670 671
         logger.info('Packages were updated successfully')
671 672
 
@@ -702,10 +703,10 @@ class EnvironmentModel(six.with_metaclass(SingletonMeta, object)):
702 703
         # ssh connection hanging on massive output from puppet run.
703 704
         cmd = '/usr/share/fuel-utils/update-master-node.sh > /dev/null 2>&1'
704 705
 
705
-        self.ssh_manager.execute_on_remote(
706
+        self.ssh_manager.check_call(
706 707
             ip=self.ssh_manager.admin_ip,
707
-            cmd=cmd,
708
-            err_msg='Update failed, inspect logs for details',
708
+            command=cmd,
709
+            error_info='Update failed, inspect logs for details',
709 710
         )
710 711
         logger.info('Update successful')
711 712
 

+ 13
- 14
fuelweb_test/models/fuel_web_client.py View File

@@ -63,7 +63,6 @@ from fuelweb_test.helpers.decorators import retry
63 63
 from fuelweb_test.helpers.decorators import update_fuel
64 64
 from fuelweb_test.helpers.decorators import upload_manifests
65 65
 from fuelweb_test.helpers.security import SecurityChecks
66
-from fuelweb_test.helpers.ssh_manager import SSHManager
67 66
 from fuelweb_test.helpers.ssl_helpers import change_cluster_ssl_config
68 67
 from fuelweb_test.helpers.ssl_helpers import copy_cert_from_master
69 68
 from fuelweb_test.helpers.uca import change_cluster_uca_config
@@ -105,9 +104,9 @@ class FuelWebClient29(object):
105 104
     """FuelWebClient."""  # TODO documentation
106 105
 
107 106
     def __init__(self, environment):
108
-        self.ssh_manager = SSHManager()
109
-        self.admin_node_ip = self.ssh_manager.admin_ip
110 107
         self._environment = environment
108
+        self.ssh_manager = environment.ssh_manager
109
+        self.admin_node_ip = self.ssh_manager.admin_ip
111 110
 
112 111
         keystone_url = "http://{0}:5000/v2.0".format(self.admin_node_ip)
113 112
 
@@ -655,7 +654,7 @@ class FuelWebClient29(object):
655 654
             if help_data.FUEL_USE_LOCAL_NTPD\
656 655
                     and ('ntp_list' not in settings)\
657 656
                     and checkers.is_ntpd_active(
658
-                        self.ssh_manager.admin_ip, public_gw):
657
+                        self.admin_node_ip, public_gw):
659 658
                 attributes['editable']['external_ntp']['ntp_list']['value'] =\
660 659
                     [public_gw]
661 660
                 logger.info("Configuring cluster #{0}"
@@ -1259,8 +1258,7 @@ class FuelWebClient29(object):
1259 1258
 
1260 1259
     @logwrap
1261 1260
     def get_ssh_for_node(self, node_name):
1262
-        return self.environment.d_env.get_ssh_to_remote(
1263
-            self.get_node_ip_by_devops_name(node_name))
1261
+        return self.environment.d_env.get_node_remote(node_name)
1264 1262
 
1265 1263
     @logwrap
1266 1264
     def get_ssh_for_role(self, nodes_dict, role):
@@ -1268,9 +1266,13 @@ class FuelWebClient29(object):
1268 1266
                            nodes_dict.keys()))[0]
1269 1267
         return self.get_ssh_for_node(node_name)
1270 1268
 
1269
+    @logwrap
1270
+    def get_ssh_for_ip(self, ip):
1271
+        return self.ssh_manager.get_remote(ip)
1272
+
1271 1273
     @logwrap
1272 1274
     def get_ssh_for_nailgun_node(self, nailgun_node):
1273
-        return self.environment.d_env.get_ssh_to_remote(nailgun_node['ip'])
1275
+        return self.get_ssh_for_ip(nailgun_node['ip'])
1274 1276
 
1275 1277
     @logwrap
1276 1278
     def is_node_discovered(self, nailgun_node):
@@ -2290,7 +2292,7 @@ class FuelWebClient29(object):
2290 2292
                           self.client.list_cluster_nodes(cluster_id)])
2291 2293
         # 'mco find' returns '1' exit code if rabbitmq is not ready
2292 2294
         out = self.ssh_manager.execute_on_remote(
2293
-            ip=self.ssh_manager.admin_ip,
2295
+            ip=self.admin_node_ip,
2294 2296
             cmd='mco find', assert_ec_equal=[0, 1])['stdout_str']
2295 2297
         ready_nodes_uids = set(out.split('\n'))
2296 2298
         unavailable_nodes = nodes_uids - ready_nodes_uids
@@ -2369,8 +2371,7 @@ class FuelWebClient29(object):
2369 2371
         # Let's find nodes where are a time skew. It can be checked on
2370 2372
         # an arbitrary one.
2371 2373
         logger.debug("Looking up nodes with a time skew and try to fix them")
2372
-        with self.environment.d_env.get_ssh_to_remote(
2373
-                online_ceph_nodes[0]['ip']) as remote:
2374
+        with self.get_ssh_for_nailgun_node(online_ceph_nodes[0]) as remote:
2374 2375
             if ceph.is_clock_skew(remote):
2375 2376
                 skewed = ceph.get_node_fqdns_w_clock_skew(remote)
2376 2377
                 logger.warning("Time on nodes {0} are to be "
@@ -2413,9 +2414,7 @@ class FuelWebClient29(object):
2413 2414
 
2414 2415
         logger.info('Waiting until Ceph service become up...')
2415 2416
         for node in online_ceph_nodes:
2416
-            with self.environment.d_env\
2417
-                    .get_ssh_to_remote(node['ip']) as remote:
2418
-
2417
+            with self.get_ssh_for_nailgun_node(node) as remote:
2419 2418
                 wait(lambda: ceph.check_service_ready(remote) is True,
2420 2419
                      interval=20, timeout=600,
2421 2420
                      timeout_msg='Ceph service is not properly started'
@@ -2425,7 +2424,7 @@ class FuelWebClient29(object):
2425 2424
         self.check_ceph_time_skew(cluster_id, offline_nodes)
2426 2425
 
2427 2426
         node = online_ceph_nodes[0]
2428
-        with self.environment.d_env.get_ssh_to_remote(node['ip']) as remote:
2427
+        with self.get_ssh_for_nailgun_node(node) as remote:
2429 2428
             if not ceph.is_health_ok(remote):
2430 2429
                 if ceph.is_pgs_recovering(remote) and len(offline_nodes) > 0:
2431 2430
                     logger.info('Ceph is being recovered after osd node(s)'

+ 1
- 1
fuelweb_test/tests/base_test_case.py View File

@@ -280,7 +280,7 @@ class TestBasic(object):
280 280
         ssh.execute_on_remote(ssh.admin_ip, cmd=cmd)
281 281
 
282 282
         self.env.wait_for_external_config()
283
-        self.env.admin_actions.modify_configs(self.env.d_env.router())
283
+        self.env.admin_actions.modify_configs(self.env.d_env.get_default_gw())
284 284
         if CUSTOM_FUEL_SETTING_YAML:
285 285
             self.env.admin_actions.update_fuel_setting_yaml(
286 286
                 CUSTOM_FUEL_SETTING_YAML)

Loading…
Cancel
Save