Force a GET operations on cloudify API
[functest.git] / functest / core / cloudify.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2018 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 """Cloudify testcase implementation."""
11
12 from __future__ import division
13
14 import logging
15 import time
16
17 from cloudify_rest_client import CloudifyClient
18
19 from functest.core import singlevm
20
21
22 class Cloudify(singlevm.SingleVm2):
23     """Cloudify Orchestrator Case."""
24
25     __logger = logging.getLogger(__name__)
26
27     filename = ('/home/opnfv/functest/images/'
28                 'cloudify-manager-premium-4.0.1.qcow2')
29     flavor_ram = 4096
30     flavor_vcpus = 2
31     flavor_disk = 50
32     username = 'centos'
33     ssh_connect_loops = 12
34     ports = [80, 443, 5671, 53333]
35
36     def __init__(self, **kwargs):
37         """Initialize Cloudify testcase object."""
38         if "case_name" not in kwargs:
39             kwargs["case_name"] = "cloudify"
40         super(Cloudify, self).__init__(**kwargs)
41         self.cfy_client = None
42
43     def prepare(self):
44         super(Cloudify, self).prepare()
45         for port in self.ports:
46             self.cloud.create_security_group_rule(
47                 self.sec.id, port_range_min=port, port_range_max=port,
48                 protocol='tcp', direction='ingress')
49
50     def execute(self):
51         """
52         Deploy Cloudify Manager.
53         """
54         self.cfy_client = CloudifyClient(
55             host=self.fip.floating_ip_address,
56             username='admin', password='admin', tenant='default_tenant',
57             api_version='v3')
58         self.__logger.info("Attemps running status of the Manager")
59         for loop in range(10):
60             try:
61                 self.__logger.debug(
62                     "status %s", self.cfy_client.manager.get_status())
63                 cfy_status = self.cfy_client.manager.get_status()['status']
64                 self.__logger.info(
65                     "The current manager status is %s", cfy_status)
66                 if str(cfy_status) != 'running':
67                     raise Exception("Cloudify Manager isn't up and running")
68                 self.cfy_client.secrets.list()
69                 self.__logger.debug("Secrets API successfully reached")
70                 break
71             except Exception:  # pylint: disable=broad-except
72                 self.__logger.info(
73                     "try %s: Cloudify Manager isn't up and running", loop + 1)
74                 time.sleep(30)
75         else:
76             self.__logger.error("Cloudify Manager isn't up and running")
77             return 1
78         self.__logger.info("Cloudify Manager is up and running")
79         return 0