예제 #1
0
    def __call__(self):
        _host = host.Host(self.insanity)
        _services = self.list_services()
        while not self.in_queue.empty():
            if self.is_stopped:
                break

            try:
                hostname = self.in_queue.get_nowait()
            except Queue.Empty:
                break

            # No service exists
            service = _services.get(hostname)
            if not service:
                unbootable_server = scenarios.UnbootableServer(
                    **{'OS-EXT-SRV-ATTR:host': hostname,
                       'metadata': {'host_id': hostname},
                       'name': hostname,
                       'status': "no nova service exists on %s"
                       % hostname})
                self.out_queue.put(unbootable_server)
                continue

            # Nova service state is bad
            unbootable_server = scenarios.UnbootableServer(
                **{'OS-EXT-SRV-ATTR:host': service.host,
                   'metadata': {'host_id': hostname},
                   'name': hostname})
            if service.state != 'up':
                unbootable_server.status = ("nova service state is %s on %s"
                                            % (service.state, hostname))
                self.out_queue.put(unbootable_server)
                continue
            if not CONF.filter_enabled and service.status != 'enabled':
                unbootable_server.status = ("nova service status is %s on %s"
                                            % (service.status, hostname))
                self.out_queue.put(unbootable_server)
                continue

            try:
                server = _host.boot_server(hostname)
                LOG.info("Sent server boot request")
            except Exception:
                LOG.exception("Failed to boot server")
                # Try again later in the queue
                self.in_queue.put(hostname)
            else:
                self.out_queue.put(server)

            self.in_queue.task_done()
            time.sleep(self.launch_wait)
        LOG.info("Finished booting servers.")
예제 #2
0
    def launch_on_hosts_missing_servers(self):
        launched_on = set()

        for server in self.servers():
            launched_on.add(getattr(server, 'OS-EXT-SRV-ATTR:host'))

        servers = []
        _host = host.Host(self._sanity)
        for hostname in self.hosts():
            if hostname in launched_on:
                continue
            servers.append(_host.boot_server(hostname))
        self._sanity.wait_for_servers(servers)
예제 #3
0
 def launch_on_one_host(self, hostname):
     _host = host.Host(self._sanity)
     servers = [_host.boot_server(hostname)]
     self._sanity.wait_for_servers(servers)
예제 #4
0
 def launch_on_some_hosts(self, hosts):
     _host = host.Host(self._sanity)
     servers = []
     for hostname in hosts:
         servers.append(_host.boot_server(hostname))
     self._sanity.wait_for_servers(servers)
예제 #5
0
    def launch_on_each_host(self):
        _host = host.Host(self._sanity)

        self._sanity.wait_for_servers(
            self._sanity.for_hosts(_host.boot_server))
예제 #6
0
def main1():
    CONF.register_cli_opt(cfg.SubCommandOpt('action', handler=add_parsers))
    CONF()

    log_level = logging.WARNING
    if CONF.verbose is True:
        log_level = logging.INFO
    if CONF.debug is True:
        log_level = logging.DEBUG
    logging.root.setLevel(log_level)

    if CONF.log_file is not None:
        file_log = logging.FileHandler(CONF.log_file)
        file_log.setFormatter(logging.Formatter(LOG_FORMAT))
        logging.root.addHandler(file_log)

    if not CONF.keystone.auth_url:
        LOG.error('You must provide a keystone auth'
                  ' url via env[OS_AUTH_URL]')
        sys.exit(1)
    if not CONF.keystone.tenant_name:
        LOG.error('You must provide a tenant name'
                  ' via env[OS_TENANT_NAME]')
        sys.exit(1)
    if not CONF.keystone.username:
        LOG.error('You must provide a username'
                  ' or user id via env[OS_USERNAME]')
        sys.exit(1)
    if not CONF.keystone.password:
        LOG.error('You must provide a password'
                  ' via env[OS_PASSWORD]')
        sys.exit(1)

    user_ns = {}
    auth_url = user_ns['OS_AUTH_URL'] = CONF.keystone.auth_url
    password = user_ns['OS_PASSWORD'] = CONF.keystone.password
    tenant = user_ns['OS_TENANT_NAME'] = CONF.keystone.tenant_name
    username = user_ns['OS_USERNAME'] = CONF.keystone.username
    endpoint_type = user_ns['OS_ENDPOINT_TYPE'] = CONF.keystone.endpoint_type
    clientmanager = user_ns['clientmanager'] = os_sdk.create_connection(
        auth_url, tenant, username, password, endpoint_type=endpoint_type)
    keystone = user_ns['keystone'] = clientmanager.identity
    nova = user_ns['nova'] = no_client.Client(
        '2', session=clientmanager.session)
    neutron = user_ns['neutron'] = clientmanager.network
    glance = user_ns['glance'] = clientmanager.image
    state = user_ns['state'] = SanityState(
        keystone, nova, glance, neutron,
        # Trim out the OSLO elements
        **{k: v for k, v in CONF.iteritems()
           if not isinstance(v, (cfg.ConfigOpts.SubCommandAttr,
                                 cfg.ConfigOpts.GroupAttr))})
    sanity = user_ns['insanity'] = SanityController(state)
    simple = user_ns['simple'] = SimpleSanity(sanity)

    # All the simple sanity functions should be local
    for k in dir(simple):
        if k.startswith('_'):
            continue
        user_ns[k] = getattr(simple, k)

    # Add for each function
    user_ns['compute'] = compute.Compute(nova)
    user_ns['network'] = network.Network(neutron, sanity)
    user_ns['host'] = host.Host(sanity)

    # Add for_ functions into user space
    for k in dir(sanity):
        if k.startswith('for_'):
            user_ns[k] = getattr(sanity, k)

    # Add wait_ functions into user space
    for k in dir(sanity):
        if k.startswith('wait_'):
            user_ns[k] = getattr(sanity, k)
    CONF.action.func(user_ns)