Distributed scenario runner, results processor and report generator
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.

main.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (c) 2016 OpenStack Foundation
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain 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,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. # implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os
  16. from oslo_config import cfg
  17. from oslo_log import log as logging
  18. import yaml
  19. from performa.engine import aggregator
  20. from performa.engine import ansible_runner
  21. from performa.engine import config
  22. from performa.engine import player
  23. from performa.engine import report
  24. from performa.engine import storage
  25. from performa.engine import utils
  26. LOG = logging.getLogger(__name__)
  27. def resolve_hosts(scenario, hosts):
  28. for k, v in hosts.items():
  29. scenario = scenario.replace('$%s' % k, ','.join(v) + ',')
  30. return scenario
  31. def main():
  32. utils.init_config_and_logging(config.MAIN_OPTS)
  33. scenario_file_path = utils.get_absolute_file_path(
  34. cfg.CONF.scenario,
  35. alias_mapper=lambda f: config.SCENARIOS + '%s.yaml' % f)
  36. scenario_raw = utils.read_file(scenario_file_path)
  37. scenario_raw = resolve_hosts(scenario_raw, cfg.CONF.hosts)
  38. scenario = yaml.safe_load(scenario_raw)
  39. base_dir = os.path.dirname(scenario_file_path)
  40. tag = cfg.CONF.tag
  41. if not tag:
  42. tag = utils.random_string()
  43. LOG.info('Using auto-generated tag "%s"', tag)
  44. runner = ansible_runner.AnsibleRunner(remote_user=cfg.CONF.remote_user)
  45. records, series = player.play_scenario(runner, scenario, tag)
  46. storage.store_data(cfg.CONF.mongo_url, cfg.CONF.mongo_db, records, series)
  47. aggregator.aggregate(scenario, cfg.CONF.mongo_url, cfg.CONF.mongo_db, tag)
  48. report.generate_report(scenario, base_dir, cfg.CONF.mongo_url,
  49. cfg.CONF.mongo_db, cfg.CONF.book, tag)
  50. if __name__ == "__main__":
  51. main()