예제 #1
0
    def setup(self, args):
        log.info("Setting up simulator configuration for %s servers in %s/" %
                 (args.server_count, args.config))

        worker_count = int(args.worker_count)

        server_count = int(args.server_count)
        if args.volume_count:
            volume_count = int(args.volume_count)
        else:
            volume_count = server_count * 2

        reset_agent_config()
        set_agent_config('copytool_fifo_directory', '/tmp')

        simulator = ClusterSimulator(args.config, args.url)
        simulator.setup(server_count, worker_count, volume_count,
                        int(args.nid_count), int(args.cluster_size),
                        int(args.psu_count), int(args.su_size))
예제 #2
0
    def setUp(self):
        super(ApiTestCaseWithTestReset, self).setUp()

        if config.get('simulator', False):
            # When we're running with the simulator, parts of the simulated
            # Copytools use agent code, and the agent code expects to find
            # a populated agent-side configuration. The safe way to handle
            # this requirement is to use mock to patch in a fresh
            # ConfigStore instance for each test run.
            try:
                from chroma_agent.config_store import ConfigStore
            except ImportError:
                raise ImportError(
                    "Cannot import agent, do you need to do a 'setup.py develop' of it?"
                )

            import mock  # Mock is only available when running the simulator, hence local inclusion
            self.mock_config = ConfigStore(tempfile.mkdtemp())
            mock.patch('chroma_agent.config', self.mock_config).start()
            from chroma_agent.action_plugins.settings_management import reset_agent_config, set_agent_config
            reset_agent_config()
            # Allow the worker to create a fifo in /tmp rather than /var/spool
            set_agent_config('copytool_fifo_directory',
                             self.COPYTOOL_TESTING_FIFO_ROOT)

            try:
                from cluster_sim.simulator import ClusterSimulator
            except ImportError:
                raise ImportError(
                    "Cannot import simulator, do you need to do a 'setup.py develop' of it?"
                )

            # The simulator's state directory will be left behind when a test fails,
            # so make sure it has a unique-per-run name
            timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S")
            state_path = 'simulator_state_%s.%s_%s' % (
                self.__class__.__name__, self._testMethodName, timestamp)
            if os.path.exists(state_path):
                raise RuntimeError(
                    "Simulator state folder already exists at '%s'!" %
                    state_path)

            # Hook up the agent log to a file
            from chroma_agent.agent_daemon import daemon_log
            handler = logging.FileHandler(
                os.path.join(config.get('log_dir', '/var/log/'),
                             'chroma_test_agent.log'))
            handler.setFormatter(
                logging.Formatter('[%(asctime)s] %(message)s',
                                  '%d/%b/%Y:%H:%M:%S'))
            daemon_log.addHandler(handler)
            daemon_log.setLevel(logging.DEBUG)

            self.simulator = ClusterSimulator(
                state_path, config['chroma_managers'][0]['server_http_url'])
            volume_count = max(
                [len(s['device_paths']) for s in self.config_servers])
            self.simulator.setup(len(self.config_servers),
                                 len(self.config_workers),
                                 volume_count,
                                 self.SIMULATOR_NID_COUNT,
                                 self.SIMULATOR_CLUSTER_SIZE,
                                 len(config['power_distribution_units']),
                                 su_size=0)
            self.remote_operations = SimulatorRemoteOperations(
                self, self.simulator)
            if self.TESTS_NEED_POWER_CONTROL:
                self.simulator.power.start()
        else:
            self.remote_operations = RealRemoteOperations(self)

        if self.quick_setup is False:
            # Ensure that all servers are up and available
            for server in self.TEST_SERVERS:
                logger.info(
                    "Checking that %s is running and restarting if necessary..."
                    % server['fqdn'])
                self.remote_operations.await_server_boot(server['fqdn'],
                                                         restart=True)
                logger.info("%s is running" % server['fqdn'])
                self.remote_operations.inject_log_message(
                    server['fqdn'], "==== "
                    "starting test %s "
                    "=====" % self)

            if config.get('reset', True):
                self.reset_cluster()
            elif config.get('soft_reset', True):
                # Reset the manager via the API
                self.wait_until_true(self.api_contactable)
                self.remote_operations.unmount_clients()
                self.api_force_clear()
                self.remote_operations.clear_ha(self.TEST_SERVERS)
                self.remote_operations.clear_lnet_config(self.TEST_SERVERS)

            if config.get('managed'):
                # Ensure that config from previous runs doesn't linger into
                # this one.
                self.remote_operations.remove_config(self.TEST_SERVERS)

                # If there are no configuration options for a given server
                # (e.g. corosync_config), then this is a noop and no config file
                # is written.
                self.remote_operations.write_config(self.TEST_SERVERS)

                # cleanup linux devices
                self.cleanup_linux_devices(self.TEST_SERVERS)

                # cleanup zfs pools
                self.cleanup_zfs_pools(
                    self.config_servers, self.CZP_EXPORTPOOLS |
                    (self.CZP_RECREATEZPOOLS if config.get(
                        'new_zpools_each_test', False) else
                     self.CZP_REMOVEDATASETS), None, True)

            # Enable agent debugging
            self.remote_operations.enable_agent_debug(self.TEST_SERVERS)

        self.wait_until_true(self.supervisor_controlled_processes_running)
        self.initial_supervisor_controlled_process_start_times = self.get_supervisor_controlled_process_start_times(
        )