def test_create_core_default(): """Test `create_core` with factory defaults.""" with temporary_config_file() as cfgfile: # std factory params core = create_core(cfgfile.name) assert isinstance(core, Core) assert core.auto_enable_auth == True
def _setup_flavor_selection_tests(extra_conf=''): # FIXME: the test does not run if this is not in the environment! os.environ['OS_AUTH_URL'] = 'http://localhost:5000/v2/' env = ['username', 'password', 'tenant_name', 'auth_url'] for name in env: os.environ['OS_' + name.upper()] = name with temporary_config_file(_const.SSH_AUTH_STANZA + _const.CLOUD_AUTH_STANZA_FULL + _const.RESOURCE_STANZA + extra_conf) as cfgfile: cfg = gc3libs.config.Configuration(cfgfile.name) resources = cfg.make_resources() cloud = resources['hobbes'] # mock novaclient's `Flavor` type using a namedtuple _Flavor = namedtuple('_Flavor', 'name vcpus ram disk'.split()) flavors = ( _Flavor(name='1cpu-4ram-hpc', vcpus=1, ram=4000, disk=100), _Flavor(name='4cpu-16ram-hpc', vcpus=4, ram=16000, disk=100), _Flavor(name='8cpu-8ram-server', vcpus=8, ram=7680, disk=100), ) cloud.client = MagicMock() cloud.client.flavors.list.return_value = flavors # `_connect` fills the flavor list cloud._connect() return cloud, flavors
def test_create_core_default(): """Test `create_core` with factory defaults.""" with temporary_config_file() as cfgfile: # std factory params core = create_core(cfgfile.name) assert_is_instance(core, Core) assert_equal(core.auto_enable_auth, True)
def _setup_flavor_selection_tests(extra_conf=''): # FIXME: the test does not run if this is not in the environment! os.environ['OS_AUTH_URL'] = 'http://localhost:5000/v2/' env = ['username', 'password', 'tenant_name', 'auth_url'] for name in env: os.environ['OS_' + name.upper()] = name with temporary_config_file( _const.SSH_AUTH_STANZA + _const.CLOUD_AUTH_STANZA_FULL + _const.RESOURCE_STANZA + extra_conf ) as cfgfile: cfg = gc3libs.config.Configuration(cfgfile.name) resources = cfg.make_resources() cloud = resources['hobbes'] # mock novaclient's `Flavor` type using a namedtuple _Flavor = namedtuple('_Flavor', 'name vcpus ram disk'.split()) flavors = ( _Flavor(name='1cpu-4ram-hpc', vcpus=1, ram=4000, disk=100), _Flavor(name='4cpu-16ram-hpc', vcpus=4, ram=16000, disk=100), _Flavor(name='8cpu-8ram-server', vcpus=8, ram=7680, disk=100), ) cloud.client = MagicMock() cloud.client.flavors.list.return_value = flavors # `_connect` fills the flavor list cloud._connect() return cloud, flavors
def test_create_core_non_default(): """Test `create_core` with non-default arguments.""" with temporary_config_file() as cfgfile: # use a specific MatchMaker instance for equality testing mm = MatchMaker() core = create_core(cfgfile.name, matchmaker=mm) assert_equal(core.auto_enable_auth, True) assert_equal(core.matchmaker, mm)
def test_create_engine_non_default2(): """Test `create_engine` with several non-default arguments.""" with temporary_config_file() as cfgfile: engine = create_engine(cfgfile.name, can_submit=False, max_in_flight=1234) assert engine.can_submit == False assert engine.max_in_flight == 1234
def test_create_engine_non_default2(): """Test `create_engine` with several non-default arguments.""" with temporary_config_file() as cfgfile: engine = create_engine(cfgfile.name, can_submit=False, max_in_flight=1234) assert_equal(engine.can_submit, False) assert_equal(engine.max_in_flight, 1234)
def test_create_core_non_default(): """Test `create_core` with non-default arguments.""" with temporary_config_file() as cfgfile: # use a specific MatchMaker instance for equality testing mm = MatchMaker() core = create_core(cfgfile.name, matchmaker=mm) assert core.auto_enable_auth == True assert core.matchmaker == mm
def test_create_engine_with_core_options(): """Test `create_engine` with a mix of Engine and Core options.""" with temporary_config_file() as cfgfile: # use a specific MatchMaker instance for equality testing mm = MatchMaker() engine = create_engine(cfgfile.name, can_submit=False, matchmaker=mm, auto_enable_auth=False) assert engine.can_submit == False assert engine._core.matchmaker == mm assert engine._core.auto_enable_auth == False
def test_create_engine_with_core_options(): """Test `create_engine` with a mix of Engine and Core options.""" with temporary_config_file() as cfgfile: # use a specific MatchMaker instance for equality testing mm = MatchMaker() engine = create_engine(cfgfile.name, can_submit=False, matchmaker=mm, auto_enable_auth=False) assert_equal(engine.can_submit, False) assert_equal(engine._core.matchmaker, mm) assert_equal(engine._core.auto_enable_auth, False)
def test_openstack_variables_are_optional(): with temporary_config_file(_const.SSH_AUTH_STANZA + _const.CLOUD_AUTH_STANZA_USE_ENV + _const.RESOURCE_STANZA) as cfgfile: # set up fake environment env = ['username', 'password', 'tenant_name', 'auth_url'] for name in env: os.environ['OS_' + name.upper()] = name # check that resource has been correctly created cfg = gc3libs.config.Configuration(cfgfile.name) resources = cfg.make_resources() assert 'hobbes' in resources cloud = resources['hobbes'] assert isinstance(cloud, OpenStackLrms) # check that values have been inherited from the environment for name in env: attr = ('os_' + name) assert hasattr(cloud, attr) assert getattr(cloud, attr) == name
def test_openstack_variables_are_optional(self): with temporary_config_file( self._const.SSH_AUTH_STANZA + self._const.CLOUD_AUTH_STANZA_USE_ENV + self._const.RESOURCE_STANZA ) as cfgfile: # set up fake environment env = ['username', 'password', 'tenant_name', 'auth_url'] for name in env: os.environ['OS_' + name.upper()] = name # check that resource has been correctly created cfg = gc3libs.config.Configuration(cfgfile.name) resources = cfg.make_resources() assert 'hobbes' in resources cloud = resources['hobbes'] assert isinstance(cloud, OpenStackLrms) # check that values have been inherited from the environment for name in env: attr = ('os_' + name) assert hasattr(cloud, attr) assert_equal(getattr(cloud, attr), name)
def test_create_core_no_auto_enable_auth(): """Test `create_core` without the "auto enable" feature.""" with temporary_config_file() as cfgfile: # std factory params core = create_core(cfgfile.name, auto_enable_auth=False) assert_equal(core.auto_enable_auth, False)
def test_create_engine_default(): """Test `create_engine` with factory defaults.""" with temporary_config_file() as cfgfile: # std factory params engine = create_engine(cfgfile.name) assert_is_instance(engine, Engine)
def test_create_engine_default(): """Test `create_engine` with factory defaults.""" with temporary_config_file() as cfgfile: # std factory params engine = create_engine(cfgfile.name) assert isinstance(engine, Engine)
def test_create_engine_non_default1(): """Test `create_engine` with one non-default argument.""" with temporary_config_file() as cfgfile: engine = create_engine(cfgfile.name, can_submit=False) assert_equal(engine.can_submit, False)
def test_create_core_no_auto_enable_auth(): """Test `create_core` without the "auto enable" feature.""" with temporary_config_file() as cfgfile: # std factory params core = create_core(cfgfile.name, auto_enable_auth=False) assert core.auto_enable_auth == False
def test_create_engine_non_default1(): """Test `create_engine` with one non-default argument.""" with temporary_config_file() as cfgfile: engine = create_engine(cfgfile.name, can_submit=False) assert engine.can_submit == False