Merge "DRAFT: model: remove vld_id not needed"
[yardstick.git] / yardstick / benchmark / scenarios / lib / create_sec_group.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 from __future__ import print_function
11 from __future__ import absolute_import
12
13 import logging
14
15 from yardstick.benchmark.scenarios import base
16 import yardstick.common.openstack_utils as op_utils
17
18 LOG = logging.getLogger(__name__)
19
20
21 class CreateSecgroup(base.Scenario):
22     """Create an OpenStack security group"""
23
24     __scenario_type__ = "CreateSecgroup"
25
26     def __init__(self, scenario_cfg, context_cfg):
27         self.scenario_cfg = scenario_cfg
28         self.context_cfg = context_cfg
29         self.options = self.scenario_cfg['options']
30
31         self.sg_name = self.options.get("sg_name", "yardstick_sec_group")
32         self.description = self.options.get("description", None)
33         self.neutron_client = op_utils.get_neutron_client()
34
35         self.setup_done = False
36
37     def setup(self):
38         """scenario setup"""
39
40         self.setup_done = True
41
42     def run(self, result):
43         """execute the test"""
44
45         if not self.setup_done:
46             self.setup()
47
48         sg_id = op_utils.create_security_group_full(self.neutron_client,
49                                                     sg_name=self.sg_name,
50                                                     sg_description=self.description)
51
52         if sg_id:
53             result.update({"sg_create": 1})
54             LOG.info("Create security group successful!")
55         else:
56             result.update({"sg_create": 0})
57             LOG.error("Create security group failed!")
58
59         try:
60             keys = self.scenario_cfg.get('output', '').split()
61         except KeyError:
62             pass
63         else:
64             values = [sg_id]
65             return self._push_to_outputs(keys, values)