def load_replace_candidate(self, filename=None, config=None): self.config_replace = True self.device.candidate_config = FortiConfig('candidate') self.device.running_config = FortiConfig('running') self._load_config(filename, config) self.device.load_config(empty_candidate=True)
def load_merge_candidate(self, filename=None, config=None): self.config_replace = False self.device.candidate_config = FortiConfig('candidate') self.device.running_config = FortiConfig('running') self._load_config(filename, config) for block in self.device.candidate_config.get_block_names(): try: self.device.load_config(path=block, empty_candidate=True) except CommandExecutionException as e: raise MergeConfigException(e.message)
class FakeFortiOSDevice: @staticmethod def read_txt_file(filename): with open(filename) as data_file: return data_file.read().splitlines() def execute_command(self, command): return self.read_txt_file('fortios/mock_data/{}.txt'.format(command.replace(' ', '_'))) def load_config(self, config_block): self.running_config = FortiConfig('running') self.running_config.parse_config_output(self.read_txt_file('fortios/mock_data/{}.txt'.format( config_block.replace(' ', '_'))))
class FakeFortiOSDevice: @staticmethod def read_txt_file(filename): with open(filename) as data_file: return data_file.read().splitlines() def execute_command(self, command): return self.read_txt_file('fortios/mock_data/{}.txt'.format( command.replace(' ', '_').replace('|', '').replace(':', ''))) def load_config(self, config_block): self.running_config = FortiConfig('running') self.running_config.parse_config_output( self.read_txt_file('fortios/mock_data/{}.txt'.format( config_block.replace(' ', '_'))))
class FakeDevice(BaseTestDouble): """Device test double.""" def open(self): pass def close(self): pass def execute_command(self, command): filename = '{}.txt'.format(self.sanitize_text(command)) full_path = self.find_file(filename) return self.read_txt_file(full_path).splitlines() def load_config(self, config_block): filename = '{}.txt'.format(self.sanitize_text(config_block)) full_path = self.find_file(filename) self.running_config = FortiConfig('running') self.running_config.parse_config_output(self.read_txt_file(full_path))
def discard_config(self): self.device.candidate_config = FortiConfig('candidate') self.device.load_config(in_candidate=True)
def load_config(self, config_block): self.running_config = FortiConfig('running') self.running_config.parse_config_output( self.read_txt_file('fortios/mock_data/{}.txt'.format( config_block.replace(' ', '_'))))
def load_config(self, config_block): self.running_config = FortiConfig('running') self.running_config.parse_config_output(self.read_txt_file('fortios/mock_data/{}.txt'.format( config_block.replace(' ', '_'))))
def load_config(self, config_block): filename = '{}.txt'.format(self.sanitize_text(config_block)) full_path = self.find_file(filename) self.running_config = FortiConfig('running') self.running_config.parse_config_output(self.read_txt_file(full_path))