Merge "Documentation for unit test project"
[functest.git] / functest / opnfv_tests / openstack / refstack_client / tempest_conf.py
1 #!/usr/bin/env python
2
3 # matthew.lijun@huawei.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 import logging
9 import os
10
11 from functest.opnfv_tests.openstack.tempest import conf_utils
12 from functest.utils import openstack_utils
13 from functest.utils.constants import CONST
14
15 """ logging configuration """
16 logger = logging.getLogger(__name__)
17
18
19 class TempestConf(object):
20     def __init__(self):
21         self.VERIFIER_ID = conf_utils.get_verifier_id()
22         self.VERIFIER_REPO_DIR = conf_utils.get_verifier_repo_dir(
23             self.VERIFIER_ID)
24         self.DEPLOYMENT_ID = conf_utils.get_verifier_deployment_id()
25         self.DEPLOYMENT_DIR = conf_utils.get_verifier_deployment_dir(
26             self.VERIFIER_ID, self.DEPLOYMENT_ID)
27         self.confpath = os.path.join(CONST.dir_functest_test,
28                                      CONST.refstack_tempest_conf_path)
29
30     def generate_tempestconf(self):
31         try:
32             openstack_utils.source_credentials(CONST.openstack_creds)
33             img_flavor_dict = conf_utils.create_tempest_resources(
34                 use_custom_images=True, use_custom_flavors=True)
35             conf_utils.configure_tempest_defcore(
36                 self.DEPLOYMENT_DIR, img_flavor_dict)
37         except Exception as e:
38             logger.error("error with generating refstack client "
39                          "reference tempest conf file: %s", e)
40
41     def main(self):
42         try:
43             self.generate_tempestconf()
44             logger.info("a reference tempest conf file generated "
45                         "at %s", self.confpath)
46         except Exception as e:
47             logger.error('Error with run: %s', e)
48
49
50 if __name__ == '__main__':
51     logging.basicConfig()
52     tempestconf = TempestConf()
53     tempestconf.main()