def parse(self): # type: (ConfigType) -> List[Core] ''' Parse configuration into list of cores Raises: :py:class:`floopcli.config.UnmetHostDependencyException`: rsync and/or docker-machine binary path does not exist :py:class:`floopcli.config.MalformedConfigException`: configuration is missing keys expected by :py:class:`floopcli.iot.core.Core` Returns: [:py:class:`floopcli.iot.core.Core`]: list of cores defined in config ''' # only handle dependency checking # let core handle host and target checking to prevent race for core in self.config: for key, val in core.items(): if key.endswith('_bin'): try: dep_path = isfile(val) if not dep_path: raise ValueError except (ValueError, TypeError): err = 'Dependency {} not found at {}'.format( key.replace('_bin', ''), str(val)) # TODO: test in an environment with unmet dependencies raise UnmetHostDependencyException(err) cores = [] for core in self.config: try: cores.append(Core(**core)) except TypeError as e: missing_key = repr(e).split(' ')[-1] err = '{} (core) has no {} (property)'.format( core['core'], missing_key) raise MalformedConfigException(err) return cores
def test_core_push_protected_target_dir_fails( fixture_protected_target_directory_config): core = Core(**fixture_protected_target_directory_config) create(core) with pytest.raises(CoreCommunicationException): push(core)
def test_core_create_invalid_core_fails(fixture_invalid_core_core_config): core = Core(**fixture_invalid_core_core_config) with pytest.raises(CoreCreateException): create(core)
def test_core_set_attributes_after_init_fails(fixture_valid_core_config): core = Core(**fixture_valid_core_config) for key in fixture_valid_core_config.keys(): with pytest.raises(CannotSetImmutableAttribute): setattr(core, key, fixture_valid_core_config[key])
def test_core_init_nonexistent_ssh_key_fails(fixture_valid_core_config): config = fixture_valid_core_config config['host_key'] = '/definitely/not/a/valid/ssh/key' with pytest.raises(SSHKeyNotFound): Core(**fixture_valid_core_config)
def test_core_nonexistent_src_dir_fails(fixture_nonexistent_source_dir_config): with pytest.raises(CoreSourceNotFound): Core(**fixture_nonexistent_source_dir_config)
def test_core_init(fixture_docker_machine_bin, fixture_valid_core_config): core = Core(**fixture_valid_core_config)
def fixture_valid_core(request): valid_config = fixture_valid_core_config(request) core = Core(**valid_config) create(core, check=True) return core