示例#1
0
    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)
示例#2
0
    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)
示例#3
0
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(' ', '_'))))
示例#4
0
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(' ', '_'))))
示例#5
0
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))
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))
示例#7
0
 def discard_config(self):
     self.device.candidate_config = FortiConfig('candidate')
     self.device.load_config(in_candidate=True)
示例#8
0
 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(' ', '_'))))
示例#9
0
 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(' ', '_'))))
示例#10
0
    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 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))