예제 #1
0
  def test_load_with_variables_no_vars(self):
    yaml_str = """
vms:
  - OLTP: {}
setup:
  - vm_group.CloneFromTemplate:
      vm_group_name: OLTP
run:
  - vm_group.PowerOn:
      vm_group_name: OLTP
    """
    data = {
      'vms': [
        {'OLTP': {}}
      ],
      'setup': [
        {'vm_group.CloneFromTemplate': {
          'vm_group_name': 'OLTP'}
        }
      ],
      'run': [
        {'vm_group.PowerOn': {
          'vm_group_name': 'OLTP'}
        }
      ],
    }
    self.assertEqual(data, scenario_parser.load_with_variables(yaml_str))
예제 #2
0
  def test_load_with_variables_out_of_bounds_high(self):
    yaml_str = """
vars:
  count:
    default: 100
    max: 200
vms: {{count}}
    """
    self.assertEqual(
      {"vars": {"count": {"max": 200,
                          "default": 100,
                          "value": 200}},
       "vms": 200},
      scenario_parser.load_with_variables(yaml_str, variables={"count": 200}))
    with self.assertRaises(ValueError) as ar:
      scenario_parser.load_with_variables(yaml_str, variables={"count": 201})
    self.assertEqual("'count' value '201' must be less than or equal to "
                     "maximum value '200'", str(ar.exception))
예제 #3
0
  def test_load_with_variables_out_of_bounds_low(self):
    yaml_str = """
vars:
  count:
    min: 5
    default: 100
vms: {{count}}
    """
    self.assertEqual(
      {"vars": {"count": {"min": 5,
                          "default": 100,
                          "value": 5}},
       "vms": 5},
      scenario_parser.load_with_variables(yaml_str, variables={"count": 5}))
    with self.assertRaises(ValueError) as ar:
      scenario_parser.load_with_variables(yaml_str, variables={"count": 4})
    self.assertEqual("'count' value '4' must be greater than or equal to "
                     "minimum value '5'", str(ar.exception))
예제 #4
0
  def test_load_with_variables_vars_parameters(self):
    yaml_str = """
vars:
  group_name:
    default: VDI
  count_per_node:
    default: 100
vms:
  - {{ group_name }}:
      nodes: all
      count_per_node: {{ count_per_node }}
setup:
  - vm_group.CloneFromTemplate:
      vm_group_name: "{{ group_name }}"
run:
  - vm_group.PowerOn:
      vm_group_name: "{{ group_name }}"
    """
    data = {
      'vars': {
        'group_name': {
          'default': 'VDI',
          'value': 'NOT VDI',
        },
        'count_per_node': {
          'default': 100,
          'value': 100,
        },
      },
      'vms': [
        {'NOT VDI': {
          'nodes': 'all',
          'count_per_node': 100,
        }}
      ],
      'setup': [
        {'vm_group.CloneFromTemplate': {
          'vm_group_name': 'NOT VDI'}
        }
      ],
      'run': [
        {'vm_group.PowerOn': {
          'vm_group_name': 'NOT VDI'}
        }
      ],
    }
    self.assertEqual(data, scenario_parser.load_with_variables(
      yaml_str, variables={"group_name": "NOT VDI"}))
예제 #5
0
  def test_load_with_variables_vars_parameters_many(self):
    variables = {
      "count_per_node": 100,
      "memory": 2,
      "type": "OLTP",
    }
    yaml_str = """
description: >
  This scenario creates {{ count_per_node }} {{type}} VMs on each node, each
  with {{ memory }}GB of memory, for a total of {{ count_per_node * memory }}GB
  per node.
vars:
  type:
    default: VDI
  count_per_node:
    default: 100
  memory:
    default: 2
vms:
  - {{ type }}:
      nodes: all
      count_per_node: {{ count_per_node }}
setup:
  - vm_group.CloneFromTemplate:
      vm_group_name: "{{ type }}"
run:
  - vm_group.PowerOn:
      vm_group_name: "{{ type }}"
    """
    data = {
      'description': 'This scenario creates 100 OLTP VMs on each node, each '
                     'with 2GB of memory, for a total of 200GB per node.\n',
      'vars': {
        'type': {
          'default': 'VDI',
          'value': 'OLTP',
        },
        'count_per_node': {
          'default': 100,
          'value': 100,
        },
        'memory': {
          'default': 2,
          'value': 2,
        }
      },
      'vms': [
        {'OLTP': {
          'nodes': 'all',
          'count_per_node': 100,
        }}
      ],
      'setup': [
        {'vm_group.CloneFromTemplate': {
          'vm_group_name': 'OLTP'}
        }
      ],
      'run': [
        {'vm_group.PowerOn': {
          'vm_group_name': 'OLTP'}
        }
      ],
    }
    self.assertEqual(data, scenario_parser.load_with_variables(
      yaml_str, variables=variables))