Exemplo n.º 1
0
 def test_file_structure(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml_safe_load(yaml_data)
     self.assertIn("protocols", alpha_data)
     self.assertTrue(VlandProtocol.accepts(alpha_data))
     level_tuple = Protocol.select_all(alpha_data)
     self.assertEqual(len(level_tuple), 2)
     self.assertEqual(
         VlandProtocol,
         [item[0] for item in sorted(level_tuple, key=lambda data: data[1])][1],
     )
     vprotocol = VlandProtocol(alpha_data, self.job_id)
     self.assertIn("arbit", vprotocol.base_group)
     self.assertNotIn("group", vprotocol.base_group)
     vprotocol.set_up()
     self.assertIn("port", vprotocol.settings)
     self.assertIn("poll_delay", vprotocol.settings)
     self.assertIn("vland_hostname", vprotocol.settings)
     self.assertEqual(
         vprotocol.base_message,
         {
             "port": vprotocol.settings["port"],
             "poll_delay": vprotocol.settings["poll_delay"],
             "host": vprotocol.settings["vland_hostname"],
             "client_name": socket.gethostname(),
         },
     )
     for name in vprotocol.names:
         vlan = vprotocol.params[name]
         self.assertIn("tags", vlan)
Exemplo n.º 2
0
    def test_configure(self):
        with open(self.filename) as yaml_data:
            alpha_data = yaml_safe_load(yaml_data)
        self.assertIn("protocols", alpha_data)
        self.assertTrue(VlandProtocol.accepts(alpha_data))
        vprotocol = VlandProtocol(alpha_data, self.job_id)
        vprotocol.set_up()
        with open(self.filename) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data, self.device, 4212, None, "")
        ret = vprotocol.configure(self.device, job)
        if not ret:
            print(vprotocol.errors)
        self.assertTrue(ret)
        nodes = {}
        for name in vprotocol.names:
            vlan = vprotocol.params[name]
            # self.assertNotIn('tags', vlan)
            uid = " ".join([vlan["switch"], str(vlan["port"])])
            nodes[uid] = name
        self.assertEqual(len(nodes.keys()), len(vprotocol.names))
        self.assertIn("vlan_one", vprotocol.names)
        self.assertNotIn("vlan_two", vprotocol.names)
        self.assertIn("switch", vprotocol.params["vlan_one"])
        self.assertIn("port", vprotocol.params["vlan_one"])
        self.assertIsNotNone(vprotocol.multinode_protocol)

        (rendered, _) = self.factory.create_device("bbb-01.jinja2")
        bbb2 = NewDevice(yaml_safe_load(rendered))
        bbb2["parameters"]["interfaces"]["eth0"]["switch"] = "192.168.0.2"
        bbb2["parameters"]["interfaces"]["eth0"]["port"] = "6"
        bbb2["parameters"]["interfaces"]["eth1"]["switch"] = "192.168.0.2"
        bbb2["parameters"]["interfaces"]["eth1"]["port"] = "4"
        self.assertEqual(
            vprotocol.params,
            {
                "vlan_one": {
                    "switch": "192.168.0.2",
                    "iface": "eth1",
                    "port": 7,
                    "tags": ["100M", "RJ45", "10M"],
                }
            },
        )
        # already configured the vland protocol in the same job
        self.assertTrue(vprotocol.configure(bbb2, job))
        self.assertEqual(
            vprotocol.params,
            {
                "vlan_one": {
                    "switch": "192.168.0.2",
                    "iface": "eth1",
                    "port": 7,
                    "tags": ["100M", "RJ45", "10M"],
                }
            },
        )
        self.assertTrue(vprotocol.valid)
        self.assertEqual(vprotocol.names, {"vlan_one": "4212vlanone"})
Exemplo n.º 3
0
    def test_configure(self):
        with open(self.filename) as yaml_data:
            alpha_data = yaml.safe_load(yaml_data)
        self.assertIn('protocols', alpha_data)
        self.assertTrue(VlandProtocol.accepts(alpha_data))
        vprotocol = VlandProtocol(alpha_data, self.job_id)
        vprotocol.set_up()
        with open(self.filename) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data, self.device, 4212, None, "")
        ret = vprotocol.configure(self.device, job)
        if not ret:
            print(vprotocol.errors)
        self.assertTrue(ret)
        nodes = {}
        for name in vprotocol.names:
            vlan = vprotocol.params[name]
            # self.assertNotIn('tags', vlan)
            uid = ' '.join([vlan['switch'], str(vlan['port'])])
            nodes[uid] = name
        self.assertEqual(len(nodes.keys()), len(vprotocol.names))
        self.assertIn('vlan_one', vprotocol.names)
        self.assertNotIn('vlan_two', vprotocol.names)
        self.assertIn('switch', vprotocol.params['vlan_one'])
        self.assertIn('port', vprotocol.params['vlan_one'])
        self.assertIsNotNone(vprotocol.multinode_protocol)

        (rendered, _) = self.factory.create_device('bbb-01.jinja2')
        bbb2 = NewDevice(yaml.safe_load(rendered))
        bbb2['parameters']['interfaces']['eth0']['switch'] = '192.168.0.2'
        bbb2['parameters']['interfaces']['eth0']['port'] = '6'
        bbb2['parameters']['interfaces']['eth1']['switch'] = '192.168.0.2'
        bbb2['parameters']['interfaces']['eth1']['port'] = '4'
        self.assertEqual(
            vprotocol.params, {
                'vlan_one': {
                    'switch': '192.168.0.2',
                    'iface': 'eth1',
                    'port': 7,
                    'tags': ['100M', 'RJ45', '10M']
                }
            })
        # already configured the vland protocol in the same job
        self.assertTrue(vprotocol.configure(bbb2, job))
        self.assertEqual(
            vprotocol.params, {
                'vlan_one': {
                    'switch': '192.168.0.2',
                    'iface': 'eth1',
                    'port': 7,
                    'tags': ['100M', 'RJ45', '10M']
                }
            })
        self.assertTrue(vprotocol.valid)
        self.assertEqual(vprotocol.names, {'vlan_one': '4212vlanone'})
Exemplo n.º 4
0
    def test_configure(self):
        with open(self.filename) as yaml_data:
            alpha_data = yaml.load(yaml_data)
        self.assertIn('protocols', alpha_data)
        self.assertTrue(VlandProtocol.accepts(alpha_data))
        vprotocol = VlandProtocol(alpha_data, self.job_id)
        vprotocol.set_up()
        with open(self.filename) as sample_job_data:
            parser = JobParser()
            job = parser.parse(sample_job_data, self.device, 4212, None, "")
        ret = vprotocol.configure(self.device, job)
        if not ret:
            print(vprotocol.errors)
        self.assertTrue(ret)
        nodes = {}
        for name in vprotocol.names:
            vlan = vprotocol.params[name]
            # self.assertNotIn('tags', vlan)
            uid = ' '.join([vlan['switch'], str(vlan['port'])])
            nodes[uid] = name
        self.assertEqual(len(nodes.keys()), len(vprotocol.names))
        self.assertIn('vlan_one', vprotocol.names)
        self.assertNotIn('vlan_two', vprotocol.names)
        self.assertIn('switch', vprotocol.params['vlan_one'])
        self.assertIn('port', vprotocol.params['vlan_one'])
        self.assertIsNotNone(vprotocol.multinode_protocol)

        bbb2 = NewDevice(os.path.join(os.path.dirname(__file__), '../devices/bbb-01.yaml'))
        bbb2['parameters']['interfaces']['eth0']['switch'] = '192.168.0.2'
        bbb2['parameters']['interfaces']['eth0']['port'] = '6'
        bbb2['parameters']['interfaces']['eth1']['switch'] = '192.168.0.2'
        bbb2['parameters']['interfaces']['eth1']['port'] = '4'
        self.assertEqual(
            vprotocol.params, {
                'vlan_one': {'switch': '192.168.0.1', 'iface': 'eth1', 'port': 7, 'tags': ['100M', 'RJ45', '10M']}
            }
        )
        # already configured the vland protocol in the same job
        self.assertTrue(vprotocol.configure(bbb2, job))
        self.assertEqual(
            vprotocol.params, {
                'vlan_one': {
                    'switch': '192.168.0.1', 'iface': 'eth1', 'port': 7, 'tags': ['100M', 'RJ45', '10M']}
            }
        )
        self.assertTrue(vprotocol.valid)
        self.assertEqual(vprotocol.names, {'vlan_one': '4212vlanone'})
Exemplo n.º 5
0
 def test_file_structure(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.load(yaml_data)
     self.assertIn('protocols', alpha_data)
     self.assertTrue(VlandProtocol.accepts(alpha_data))
     level_tuple = Protocol.select_all(alpha_data)
     self.assertEqual(len(level_tuple), 2)
     self.assertEqual(
         VlandProtocol,
         [
             item[0] for item in sorted(level_tuple, key=lambda data: data[1])
         ][1]
     )
     vprotocol = VlandProtocol(alpha_data, self.job_id)
     self.assertIn(
         'arbit',
         vprotocol.base_group,
     )
     self.assertNotIn(
         'group',
         vprotocol.base_group,
     )
     vprotocol.set_up()
     self.assertIn('port', vprotocol.settings)
     self.assertIn('poll_delay', vprotocol.settings)
     self.assertIn('vland_hostname', vprotocol.settings)
     self.assertEqual(
         vprotocol.base_message,
         {
             "port": vprotocol.settings['port'],
             "poll_delay": vprotocol.settings["poll_delay"],
             "host": vprotocol.settings['vland_hostname'],
             "client_name": socket.gethostname(),
         }
     )
     for name in vprotocol.names:
         vlan = vprotocol.params[name]
         self.assertIn('tags', vlan)