def test_create_networks_from_config(self):
        manager = None
        config = None
        sw_name = self.rpname
        try:
            config = TopologyReader(self.config_path)
            manager = Manager.Creator(manager_address=config.manager_address,
                                      manager_user=config.manager_user,
                                      manager_password=config.manager_password)

            shared_switch = Switch(self.rpname)
            networks = config.get_networks()

            #destroy isolated networks
            if shared_switch:
                shared_switch.destroy(manager, config.host_name)

            for net in networks:
                if net.isolated:
                    Switch(self.rpname + '_' + net.name).destroy(manager, config.host_name)

            shared_switch.create(manager, config.host_name)

            for net in networks:
                if net.isolated:
                    sw_name = self.rpname + '_' + net.name
                    Switch(sw_name).create(manager, config.host_name).add_network(net, manager, config.host_name)
                else:
                    shared_switch.add_network(net, manager, config.host_name)

        except Manager.CreatorException as error:
            self.assertTrue(False, error.message)
        except Exception as error:
            self.assertTrue(False, error.message)
    def test_create_and_destroy_some_networks(self):
        switch = Switch(self.switch_name, self.switch_ports)
        try:
            # create switch
            try:
                switch.create(self.manager, self.host_name)
            except Manager.ExistenceException:
                pass

            # create networks
            networks = []
            networks.append(Network(name=self.network_name + '1', vlan=self.vlan, promiscuous=False))
            networks.append(Network(name=self.network_name + '2', vlan=self.vlan, promiscuous=False))
            networks.append(Network(name=self.network_name + '3', vlan=self.vlan, promiscuous=False))

            # add networks
            for net in networks:
                try:
                    switch.add_network(network=net, manager=self.manager, host_name=self.host_name)
                except Manager.ExistenceException:
                    pass

            # destroy switch
            try:
                switch.destroy(manager=self.manager, host_name=self.host_name)
            except Manager.ExistenceException:
                pass

        except Manager.CreatorException as error:
            self.assertTrue(False, error.message)
 def test_create_and_destroy_switch(self):
     switch = Switch(self.switch_name, self.switch_ports)
     try:
         try:
             switch.create(self.manager, self.host_name)
         except Manager.ExistenceException:
             pass
         try:
             switch.destroy(manager=self.manager, host_name=self.host_name)
         except Manager.ExistenceException:
             pass
     except Manager.CreatorException as error:
         self.assertTrue(False, error.message)
    def test_add_network(self):
        switch = Switch(self.switch_name, self.switch_ports)
        try:
            # create switch
            try:
                switch.create(self.manager, self.host_name)
            except Manager.ExistenceException:
                pass

            # add network
            try:
                network = Network(name=self.network_name, vlan=self.vlan, promiscuous=False)
                switch.add_network(network=network, manager=self.manager, host_name=self.host_name)
            except Manager.ExistenceException as error:
                self.assertTrue(True, error.message)

            # destroy switch
            try:
                switch.destroy(manager=self.manager, host_name=self.host_name)
            except Manager.ExistenceException:
                pass
        except Manager.CreatorException as error:
            self.assertTrue(False, error.message)