예제 #1
0
 def test_from_path_packaged_scenarios_small_large_clusters(self):
   three_node_cluster = mock_cluster(3)
   one_hundred_twenty_eight_node_cluster = mock_cluster(128)
   for path in Scenario.find_configuration_files():
     scenario_parser.from_path(
       path, cluster=three_node_cluster)
     scenario_parser.from_path(
       path, cluster=one_hundred_twenty_eight_node_cluster)
예제 #2
0
 def test_from_path_packaged_scenarios(self):
   for path in Scenario.find_configuration_files():
     scenario = scenario_parser.from_path(path)
     first_setup_step = scenario.steps[Phase.SETUP][0]
     self.assertIsInstance(
       first_setup_step, CleanUp,
       "The first step in the setup phase should be cluster.CleanUp "
       "(path: %s, found: %s)" % (path, first_setup_step))
예제 #3
0
def from_path(path, vars=None, *args, **kwargs):
  """Read a scenario configuration and construct a new scenario instance.

  Args:
    path (basestring): Path to a configuration file. `path` may be a directory
      containing a single configuration file.
    *args: Arguments passed to Scenario __init__.
    **kwargs: Arguments passed to Scenario __init__.

  Returns:
    Scenario: A new scenario instance.
  """
  # If path is a directory, find a configuration file inside that directory.
  if os.path.isdir(path):
    paths = Scenario.find_configuration_files(path)
    if not paths:
      raise ValueError("No configuration files found at '%s'" % path)
    elif len(paths) > 1:
      raise ValueError("Multiple configuration files found at '%s': %r" %
                       (path, paths))
    else:
      path = paths[0]
  # Parse the configuration file and construct a new scenario.
  directory, filename = os.path.split(path)
  extension = os.path.splitext(filename)[1]
  if extension.lower() in [".yml", ".yaml"]:
    with open(path) as config_file:
      try:
        scenario = from_yaml_str(config_file.read(), *args,
                                 vars=vars, source_directory=directory, **kwargs)
      except yaml.parser.ParserError as err:
        raise CurieTestException("Unable to parse YAML at path %r, check "
                                 "syntax: %r" % (path, str(err)))
  else:
    raise ValueError("Invalid file type '%s'" % path)
  return scenario
예제 #4
0
 def test_from_path_readonly(self):
   path = Scenario.find_configuration_files()[0]
   scenario = scenario_parser.from_path(path, readonly=True)
   self.assertTrue(scenario.readonly)
   scenario = scenario_parser.from_path(path, readonly=False)
   self.assertFalse(scenario.readonly)