Fuel CCP - Tests sub-project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base_test.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright 2016 Mirantis, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. from fuel_ccp_tests import logger
  15. LOG = logger.logger
  16. LOG.addHandler(logger.console)
  17. class SystemBaseTest(object):
  18. """SystemBaseTest contains setup/teardown for environment creation"""
  19. def calico_ipip_exists(self, underlay):
  20. """Check if ipip is in calico pool config
  21. :param underlay: fuel_ccp_tests.managers.UnderlaySSHManager
  22. """
  23. cmd = "calicoctl pool show | grep ipip"
  24. for node_name in underlay.node_names():
  25. underlay.sudo_check_call(cmd, node_name=node_name)
  26. def required_images_exists(self, node_name, underlay, required_images):
  27. """Check if there are all base containers on node
  28. :param node_name: string
  29. :param underlay: fuel_ccp_tests.managers.UnderlaySSHManager
  30. :param required_images: list
  31. """
  32. cmd = "docker ps --no-trunc --format '{{.Image}}'"
  33. result = underlay.sudo_check_call(cmd, node_name=node_name)
  34. images = [x.split(":")[0] for x in result['stdout']]
  35. assert set(required_images) < set(images),\
  36. "Running containers check failed on node '{}'".format(node_name)
  37. def check_list_required_images(self, underlay, required_images):
  38. """Check running containers on each node
  39. :param underlay: fuel_ccp_tests.managers.UnderlaySSHManager
  40. :param required_images: list
  41. """
  42. LOG.info("Check that required containers exist")
  43. for node_name in underlay.node_names():
  44. self.required_images_exists(node_name, underlay, required_images)
  45. def check_number_kube_nodes(self, underlay, k8sclient):
  46. """Check number of slaves"""
  47. LOG.info("Check number of nodes")
  48. k8s_nodes = k8sclient.nodes.list()
  49. node_names = underlay.node_names()
  50. assert len(k8s_nodes) == len(node_names),\
  51. "Check number k8s nodes failed!"
  52. def check_etcd_health(self, underlay):
  53. node_names = underlay.node_names()
  54. cmd = "etcdctl cluster-health | grep -c 'got healthy result'"
  55. etcd_nodes = underlay.sudo_check_call(
  56. cmd, node_name=node_names[0])['stdout'][0]
  57. assert int(etcd_nodes) == len(node_names),\
  58. "Number of etcd nodes is {0}," \
  59. " should be {1}".format(int(etcd_nodes), len(node_names))
  60. def create_env_snapshot(self, name, hardware, description=None):
  61. hardware.create_snapshot(name, description=description)