Esempio 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)
Esempio 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"})
Esempio 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'})
Esempio n. 4
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)
Esempio n. 5
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'})
Esempio n. 6
0
 def demo(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml_safe_load(yaml_data)
     vprotocol = VlandProtocol(alpha_data, 422)
     vprotocol.settings = vprotocol.read_settings()
     self.assertIn("port", vprotocol.settings)
     self.assertIn("poll_delay", vprotocol.settings)
     self.assertIn("vland_hostname", vprotocol.settings)
     vprotocol.base_message = {
         "port": vprotocol.settings["port"],
         "poll_delay": vprotocol.settings["poll_delay"],
         "host": vprotocol.settings["vland_hostname"],
         "client_name": socket.gethostname(),
     }
     count = 0
     print("\nTesting vland live using connections.")
     for friendly_name in vprotocol.parameters["protocols"][vprotocol.name]:
         print("Processing VLAN: %s" % friendly_name)
         vprotocol.names[friendly_name] = vprotocol.base_group + "%02d" % count
         count += 1
         vprotocol.vlans[friendly_name], tag = vprotocol._create_vlan(friendly_name)
         print(
             "[%s] Created vlan with id %s"
             % (friendly_name, vprotocol.vlans[friendly_name])
         )
         print("[%s] tag: %s" % (friendly_name, tag))
         for hostname in vprotocol.parameters["protocols"][vprotocol.name][
             friendly_name
         ]:
             params = vprotocol.parameters["protocols"][vprotocol.name][
                 friendly_name
             ][hostname]
             print(
                 "[%s] to use switch %s and port %s"
                 % (friendly_name, params["switch"], params["port"])
             )
             self.assertIn("switch", params)
             self.assertIn("port", params)
             self.assertIsNotNone(params["switch"])
             self.assertIsNotNone(params["port"])
             switch_id = vprotocol._lookup_switch_id(params["switch"])
             self.assertIsNotNone(switch_id)
             print("[%s] Using switch ID %s" % (friendly_name, switch_id))
             port_id = vprotocol._lookup_port_id(switch_id, params["port"])
             print(
                 "%s Looked up port ID %s for %s"
                 % (friendly_name, port_id, params["port"])
             )
             vprotocol._set_port_onto_vlan(vprotocol.vlans[friendly_name], port_id)
             vprotocol.ports.append(port_id)
     print("Finalising - tearing down vlans")
     vprotocol.finalise_protocol()
Esempio n. 7
0
 def demo(self):
     with open(self.filename) as yaml_data:
         alpha_data = yaml.load(yaml_data)
     vprotocol = VlandProtocol(alpha_data, 422)
     vprotocol.settings = vprotocol.read_settings()
     self.assertIn('port', vprotocol.settings)
     self.assertIn('poll_delay', vprotocol.settings)
     self.assertIn('vland_hostname', vprotocol.settings)
     vprotocol.base_message = {
         "port": vprotocol.settings['port'],
         "poll_delay": vprotocol.settings["poll_delay"],
         "host": vprotocol.settings['vland_hostname'],
         "client_name": socket.gethostname(),
     }
     count = 0
     print("\nTesting vland live using connections.")
     for friendly_name in vprotocol.parameters['protocols'][vprotocol.name]:
         print("Processing VLAN: %s" % friendly_name)
         vprotocol.names[friendly_name] = vprotocol.base_group + '%02d' % count
         count += 1
         vprotocol.vlans[friendly_name], tag = vprotocol._create_vlan(friendly_name)
         print("[%s] Created vlan with id %s" % (friendly_name, vprotocol.vlans[friendly_name]))
         print("[%s] tag: %s" % (friendly_name, tag))
         for hostname in vprotocol.parameters['protocols'][vprotocol.name][friendly_name]:
             params = vprotocol.parameters['protocols'][vprotocol.name][friendly_name][hostname]
             print("[%s] to use switch %s and port %s" % (friendly_name, params['switch'], params['port']))
             self.assertIn('switch', params)
             self.assertIn('port', params)
             self.assertIsNotNone(params['switch'])
             self.assertIsNotNone(params['port'])
             switch_id = vprotocol._lookup_switch_id(params['switch'])
             self.assertIsNotNone(switch_id)
             print("[%s] Using switch ID %s" % (friendly_name, switch_id))
             port_id = vprotocol._lookup_port_id(switch_id, params['port'])
             print("%s Looked up port ID %s for %s" % (friendly_name, port_id, params['port']))
             vprotocol._set_port_onto_vlan(vprotocol.vlans[friendly_name], port_id)
             vprotocol.ports.append(port_id)
     print("Finalising - tearing down vlans")
     vprotocol.finalise_protocol()