Exemplo n.º 1
0
 def test_err(self):
     err_yaml = {
         'acls': {
             'patchit': [{
                 'rule': {
                     'actions': {
                         'output': {
                             'ports': [1001]
                         }
                     }
                 }
             }]
         },
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'stack': {
                     'priority': 1
                 },
                 'interfaces': {
                     1: {
                         'native_vlan': 100,
                         'acls_in': ['patchit']
                     }
                 }
             }
         }
     }
     response = self.client.set_config_file(
         yaml_dump(err_yaml),
         config_filename=self.default_config,
         merge=False)
     assert response is None
Exemplo n.º 2
0
 def test_del_dps(self):
     three_dps_yaml = {
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'stack': {
                     'priority': 1
                 },
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     },
                     2: {
                         'stack': {
                             'dp': 'ovs2',
                             'port': 2
                         }
                     }
                 }
             },
             'ovs2': {
                 'dp_id': 2,
                 'hardware': 'Open vSwitch',
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     },
                     2: {
                         'stack': {
                             'dp': 'ovs1',
                             'port': 2
                         }
                     }
                 }
             },
             'ovs3': {
                 'dp_id': 3,
                 'hardware': 'Open vSwitch',
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     }
                 }
             }
         }
     }
     assert self.client.set_config_file(yaml_dump(three_dps_yaml),
                                        config_filename=self.default_config,
                                        merge=False)
     response = self.client.del_dps(['ovs2'])
     assert response is not None
     assert self.client.del_dp_interfaces([('ovs3', [1])],
                                          delete_empty_dp=True) is not None
     del three_dps_yaml['dps']['ovs3']
     del three_dps_yaml['dps']['ovs2']
     del three_dps_yaml['dps']['ovs1']['interfaces'][2]
     result = self.client.get_config_file(
         config_filename=self.default_config)
     assert three_dps_yaml == result
Exemplo n.º 3
0
 def test_vlan_out_acl(self):
     one_dp_yaml = {
         'acls': {
             'denyit': [{
                 'rule': {}
             }]
         },
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'egress_pipeline': True,
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     }
                 }
             }
         },
     }
     response = self.client.set_config_file(
         yaml_dump(one_dp_yaml),
         config_filename=self.default_config,
         merge=False)
     assert response is not None
     response = self.client.set_vlan_out_acl('100', 'denyit')
     assert response is not None
     acl_yaml = self.client.get_config_file(
         config_filename=self.default_config)
     assert acl_yaml['vlans'][100]['acl_out'] == 'denyit'
Exemplo n.º 4
0
 def test_copro(self):
     one_dp_yaml = {
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     }
                 }
             }
         },
     }
     response = self.client.set_config_file(
         yaml_dump(one_dp_yaml),
         config_filename=self.default_config,
         merge=False)
     assert response is not None
     response = self.client.make_coprocessor_port('ovs1', 1)
     assert response is not None
     copro_yaml = self.client.get_config_file(
         config_filename=self.default_config)
     assert copro_yaml['dps']['ovs1']['interfaces'][1] == {
         'description': 'coprocessor',
         'coprocessor': {
             'strategy': 'vlan_vid'
         }
     }
 def del_config_from_file(self, config_yaml_keys, config_filename=None):
     """Delete a key from YAML config file."""
     if isinstance(config_yaml_keys, list):
         config_yaml_keys = yaml_dump(config_yaml_keys)
     return self._call(
         self._stub.DelConfigFromFile,
         faucetconfrpc_pb2.DelConfigFromFileRequest(
             config_filename=config_filename,
             config_yaml_keys=config_yaml_keys))
Exemplo n.º 6
0
 def test_remote_mirror_port(self):
     stack_dps_yaml = {
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'stack': {
                     'priority': 1
                 },
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     },
                     2: {
                         'stack': {
                             'dp': 'ovs2',
                             'port': 2
                         }
                     }
                 }
             },
             'ovs2': {
                 'dp_id': 2,
                 'hardware': 'Open vSwitch',
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     },
                     2: {
                         'stack': {
                             'dp': 'ovs1',
                             'port': 2
                         }
                     }
                 }
             }
         }
     }
     assert self.client.set_config_file(yaml_dump(stack_dps_yaml),
                                        config_filename=self.default_config,
                                        merge=False)
     response = self.client.set_remote_mirror_port('ovs2', 3, 999, 'ovs1',
                                                   1)
     assert response is not None
     response = self.client.get_config_file(
         config_filename=self.default_config)
     assert (response['dps']['ovs2']['interfaces'][3] == {
         'acls_in': ['remote-mirror-999-ovs1-1'],
         'coprocessor': {
             'strategy': 'vlan_vid'
         },
         'description': 'loopback'
     })
Exemplo n.º 7
0
 def test_dps_empty(self):
     dps_yaml = {
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     },
                 },
             },
         },
     }
     assert self.client.set_config_file(yaml_dump(dps_yaml),
                                        config_filename=self.default_config,
                                        merge=False)
     response = self.client.del_dps(['ovs1'])
     assert response is not None
     assert self.client.set_config_file(yaml_dump(dps_yaml),
                                        config_filename=self.default_config,
                                        merge=False)
Exemplo n.º 8
0
    def test_get_acl_names(self):
        include_name = os.path.join(self.tmpdir, 'include.yaml')
        include_yaml = yaml_load(
            '{acls: {anotheracl: [{rule: {actions: {allow: 0}}}]}}')
        acl_test_yaml = yaml_load("""
        {dps: {ovs: {
            dp_id: 1,
            hardware: Open vSwitch,
            interfaces: {
                1: {native_vlan: 100, acls_in: []},
                2: {native_vlan: 100},
                3: {output_only: true, mirror: [1]}}}},
         acls: {test: [{rule: {actions: {allow: 0}}}]},
         include: [%s]}
        """ % os.path.basename(include_name))

        with open(os.path.join(self.tmpdir, self.default_config),
                  'w') as test_yaml_file:
            test_yaml_file.write(yaml_dump(acl_test_yaml))  # pytype: disable=wrong-arg-types
        with open(include_name, 'w') as test_yaml_file:
            test_yaml_file.write(yaml_dump(include_yaml))  # pytype: disable=wrong-arg-types
        response = self.client.get_acl_names()
        assert response.acl_name == ["test", "anotheracl"]
 def set_config_file(self,
                     config_yaml,
                     config_filename=None,
                     merge=True,
                     del_config_yaml_keys=''):
     """Set a YAML config file."""
     if isinstance(config_yaml, dict):
         config_yaml = yaml_dump(config_yaml)
     return self._call(
         self._stub.SetConfigFile,
         faucetconfrpc_pb2.SetConfigFileRequest(
             config_filename=config_filename,
             config_yaml=config_yaml,
             merge=merge,
             del_config_yaml_keys=del_config_yaml_keys))
Exemplo n.º 10
0
 def test_empty(self):
     os.remove(os.path.join(self.tmpdir, self.default_config))
     one_dp_yaml = {
         'dps': {
             'ovs1': {
                 'dp_id': 1,
                 'hardware': 'Open vSwitch',
                 'stack': {
                     'priority': 1
                 },
                 'interfaces': {
                     1: {
                         'native_vlan': 100
                     }
                 }
             }
         },
     }
     response = self.client.set_config_file(
         yaml_dump(one_dp_yaml),
         config_filename=self.default_config,
         merge=True)
     assert response is not None
Exemplo n.º 11
0
def yaml_sanity():
    """Ensure YAML libraries present."""
    test_dict = {'test': 'value'}
    test_yaml = yaml_dump(test_dict)
    assert yaml_load(test_yaml) == test_dict