Example #1
0
    def initialize(self):
        LOG.debug("Initializing Ansible ML2 driver")

        # Get ML2 config
        self.ml2config = config.Config()

        # Build a network runner inventory object
        # and instatiate network runner
        _inv = Inventory()
        _inv.deserialize({'all': {'hosts': self.ml2config.inventory}})
        self.net_runr = net_runr_api.NetworkRunner(_inv)

        # build the extra_params dict.
        # this holds extra config params per host passed to network runner
        self.extra_params = {}
        for host_name in self.ml2config.inventory:
            self.extra_params[host_name] = {}
            for i in c.EXTRA_PARAMS:
                if i in self.ml2config.inventory[host_name]:
                    self.extra_params[host_name][i] = \
                        self.ml2config.inventory[host_name].get(i)

        self.coordinator = coordination.get_coordinator(
            cfg.CONF.ml2_ansible.coordination_uri,
            '{}-{}'.format(CONF.host, os.getpid()))

        # the heartbeat will have the default timeout of 30 seconds
        # that can be changed per-driver. Both Redis and etcd drivers
        # use 30 second timeouts.
        self.coordinator.start(start_heart=True)
        LOG.debug("Ansible ML2 coordination started via uri %s",
                  cfg.CONF.ml2_ansible.coordination_uri)

        self.trunk_driver = trunk_driver.NetAnsibleTrunkDriver.create(self)
Example #2
0
def main():
    # collect information for the run.
    args = get_parser_args()
    inv_yaml = get_inv_yaml(args)
    hosts = inv_yaml['all']['hosts']
    hostname = inv_yaml['all']['children'][HOSTNAME]['hosts'].popitem()[0]
    net_os = hosts[hostname]['ansible_network_os']
    port = PORTS[net_os]

    # build the inventory object
    inventory = Inventory()
    inventory.deserialize(inv_yaml)

    # execute the tests
    run_tests(inventory, hostname, port, net_os in TRUNK_SUPPORT, net_os
              in STP_EDGE_SUPPORT)
Example #3
0
    def setUp(self):
        super(NetworkRunnerTestCase, self).setUp()

        self.testhost = 'testhost'
        self.testport = 'port123'
        self.testvlan = 37
        self.testvlans = [73, 7, 3]

        inventory = Inventory()
        self.net_runr = api.NetworkRunner(inventory=inventory)
Example #4
0
    def setUp(self):
        super(NetworkRunnerTestCase, self).setUp()

        self.testhost = 'testhost'
        self.testport = 'port123'
        self.testvlan = 37
        self.testvlans = [73, 7, 3]

        self.inventory = Inventory()
        self.net_runr = api.NetworkRunner(inventory=self.inventory)

        pb = Playbook()
        self.play = pb.new(hosts=(self.testhost), gather_facts=False)
        self.task = self.play.tasks.new(action=api.IMPORT_ROLE)
Example #5
0
    def test_empty_inventory(self):
        inventory = Inventory()
        self.assertEqual(type(inventory), Inventory)

        serialized_inv = inventory.serialize()
        self.assertEqual(serialized_inv, EMPTY_INV)

        inventory.deserialize(EMPTY_INV)
        self.assertEqual(inventory, Inventory())
Example #6
0
 def __init__(self, inventory=None):
     if inventory is not None:
         assert isinstance(inventory, Inventory)
     self.inventory = inventory or Inventory()