def check_one_host_parsing(self, monkeypatch): self._vagrant_ssh_data = self.two_hosts monkeypatch.setattr( "ducktape.cluster.vagrant.VagrantCluster._vagrant_ssh_config", lambda vc: (self._vagrant_ssh_data, None)) monkeypatch.setattr("ducktape.cluster.vagrant.VagrantCluster._is_aws", lambda vc: False) monkeypatch.setattr( "ducktape.cluster.vagrant.VagrantCluster._externally_routable_ip", lambda vc, is_aws, node_account: "127.0.0.1") cluster = VagrantCluster() assert (cluster.num_available_nodes() == 2) node1, node2 = cluster.request(2) assert (node1.account.hostname == "worker1") assert (node1.account.user == "vagrant") assert ( node1.account.ssh_args.strip() == "-o 'HostName 127.0.0.1' -o 'Port 2222' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker1/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'" ) assert (node1.account.ssh_hostname == '127.0.0.1') assert (node2.account.hostname == "worker2") assert (node2.account.user == "vagrant") assert ( node2.account.ssh_args.strip() == "-o 'HostName 127.0.0.2' -o 'Port 2200' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker2/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'" ) assert (node2.account.ssh_hostname == '127.0.0.2')
def check_cluster_file_read(self, monkeypatch): """check the behavior of VagrantCluster when cluster_file is specified and the file exists. VagrantCluster should read cluster information from cluster_file. """ self._set_monkeypatch_attr(monkeypatch) # To verify that VagrantCluster reads cluster information from the cluster_file, the # content in the file is intentionally made different from that returned by _vagrant_ssh_config(). nodes_expected = [] node1_expected = { "externally_routable_ip": "127.0.0.3", "ssh_config": { "host": "worker3", "hostname": "127.0.0.3", "user": "******", "port": 2222, "password": "******", "identityfile": "/path/to/identfile3" } } nodes_expected.append(node1_expected) node2_expected = { "externally_routable_ip": "127.0.0.2", "ssh_config": { "host": "worker2", "hostname": "127.0.0.2", "user": "******", "port": 2223, "password": None, "identityfile": "/path/to/indentfile2" } } nodes_expected.append(node2_expected) cluster_json_expected = {} cluster_json_expected["nodes"] = nodes_expected json.dump(cluster_json_expected, open(self.cluster_file, 'w+'), indent=2, separators=(',', ': '), sort_keys=True) # Load the cluster from the json file we just created cluster = VagrantCluster(cluster_file=self.cluster_file, is_type_based=False) assert len(cluster) == 2 assert cluster.num_available_nodes() == 2 node2, node3 = cluster.alloc(Service.setup_cluster_spec(num_nodes=2)) assert node3.account.hostname == "worker2" assert node3.account.user == "vagrant" assert node3.account.ssh_hostname == '127.0.0.2' assert node3.account.ssh_config.to_json() == node2_expected["ssh_config"] assert node2.account.hostname == "worker3" assert node2.account.user == "vagrant" assert node2.account.ssh_hostname == '127.0.0.3' assert node2.account.ssh_config.to_json() == node1_expected["ssh_config"]
def check_cluster_file_write(self, monkeypatch): """check the behavior of VagrantCluster when cluster_file is specified but the file doesn't exist. VagrantCluster should read cluster information from _vagrant_ssh_config() and write the information to cluster_file. """ self._set_monkeypatch_attr(monkeypatch) assert not os.path.exists(self.cluster_file) cluster = VagrantCluster(cluster_file=self.cluster_file, is_type_based=False) cluster_json_expected = {} nodes = [ { "externally_routable_ip": node_account.externally_routable_ip, "ssh_config": { "host": node_account.ssh_config.host, "hostname": node_account.ssh_config.hostname, "user": node_account.ssh_config.user, "identityfile": node_account.ssh_config.identityfile, "password": node_account.ssh_config.password, "port": node_account.ssh_config.port } } for node_account in cluster._available_accounts ] cluster_json_expected["nodes"] = nodes cluster_json_actual = json.load(open(os.path.abspath(self.cluster_file))) assert cluster_json_actual == cluster_json_expected
def check_one_host_parsing(self, monkeypatch): """check the behavior of VagrantCluster when cluster_file is not specified. VagrantCluster should read cluster information from _vagrant_ssh_config(). """ self._set_monkeypatch_attr(monkeypatch) cluster = VagrantCluster(is_type_based=False) assert len(cluster) == 2 assert cluster.num_available_nodes() == 2 node1, node2 = cluster.alloc(Service.setup_cluster_spec(num_nodes=2)) assert node1.account.hostname == "worker1" assert node1.account.user == "vagrant" assert node1.account.ssh_hostname == '127.0.0.1' assert node2.account.hostname == "worker2" assert node2.account.user == "vagrant" assert node2.account.ssh_hostname == '127.0.0.2'
def check_cluster_file_read(self, monkeypatch): """check the behavior of VagrantCluster when cluster_file is specified and the file exists. VagrantCluster should read cluster information from cluster_file. """ self._set_monkeypatch_attr(monkeypatch) # To verify that VagrantCluster reads cluster information from the cluster_file, the # content in the file is intentionally made different from that returned by _vagrant_ssh_config(). nodes = [] nodes.append({ "hostname": "worker2", "ssh_hostname": "127.0.0.2", "user": "******", "ssh_args": "-o 'HostName 127.0.0.2' -o 'Port 2222' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker2/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'", "externally_routable_ip": "127.0.0.2" }) nodes.append({ "hostname": "worker3", "ssh_hostname": "127.0.0.3", "user": "******", "ssh_args": "-o 'HostName 127.0.0.3' -o 'Port 2223' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker3/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'", "externally_routable_ip": "127.0.0.3" }) cluster_json_expected = {} cluster_json_expected["nodes"] = nodes json.dump(cluster_json_expected, open(self.cluster_file, 'w+'), indent=2, separators=(',', ': '), sort_keys=True) cluster = VagrantCluster(cluster_file=self.cluster_file) os.remove(self.cluster_file) assert len(cluster) == 2 assert cluster.num_available_nodes() == 2 node1, node2 = cluster.request(2) assert node1.account.hostname == "worker2" assert node1.account.user == "vagrant" assert node1.account.ssh_args.strip() == "-o 'HostName 127.0.0.2' -o 'Port 2222' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker2/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'" assert node1.account.ssh_hostname == '127.0.0.2' assert node2.account.hostname == "worker3" assert node2.account.user == "vagrant" assert node2.account.ssh_args.strip() == "-o 'HostName 127.0.0.3' -o 'Port 2223' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker3/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'" assert node2.account.ssh_hostname == '127.0.0.3'
def main(): """Ducktape entry point. This contains top level logic for ducktape command-line program which does the following: Discover tests Initialize cluster for distributed services Run tests Report a summary of all results """ args = parse_args() # Make .ducktape directory where metadata such as the last used session_id is stored if not os.path.isdir(ConsoleConfig.METADATA_DIR): os.makedirs(ConsoleConfig.METADATA_DIR) # Generate a shared 'global' identifier for this test run and create the directory # in which all test results will be stored session_id = generate_session_id(ConsoleConfig.SESSION_ID_FILE) results_dir = generate_results_dir(session_id) setup_results_directory(results_dir, session_id) session_context = SessionContext(session_id, results_dir, cluster=None, args=args) # Discover and load tests to be run extend_import_paths(args.test_path) loader = TestLoader(session_context) try: test_classes = loader.discover(args.test_path) except LoaderException as e: print "Failed while trying to discover tests: {}".format(e) sys.exit(1) if args.collect_only: print test_classes sys.exit(0) # Initializing the cluster is slow, so do so only if # tests are sure to be run session_context.cluster = VagrantCluster() # Run the tests runner = SerialTestRunner(session_context, test_classes) test_results = runner.run_all_tests() # Report results # TODO command-line hook for type of reporter reporter = SimpleStdoutReporter(test_results) reporter.report() reporter = SimpleFileReporter(test_results) reporter.report() # Generate HTML reporter reporter = HTMLReporter(test_results) reporter.report() if not test_results.get_aggregate_success(): sys.exit(1)
def check_one_host_parsing(self, monkeypatch): self._vagrant_ssh_data = self.two_hosts monkeypatch.setattr("ducktape.cluster.vagrant.VagrantCluster._vagrant_ssh_config", lambda vc: (self._vagrant_ssh_data, None)) monkeypatch.setattr("ducktape.cluster.vagrant.VagrantCluster._is_aws", lambda vc: False) monkeypatch.setattr("ducktape.cluster.vagrant.VagrantCluster._externally_routable_ip", lambda vc, is_aws, node_account: "127.0.0.1") cluster = VagrantCluster() assert(cluster.num_available_nodes() == 2) node1, node2 = cluster.request(2) assert(node1.account.hostname == "worker1") assert(node1.account.user == "vagrant") assert(node1.account.ssh_args.strip() == "-o 'HostName 127.0.0.1' -o 'Port 2222' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker1/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'") assert(node1.account.ssh_hostname == '127.0.0.1') assert(node2.account.hostname == "worker2") assert(node2.account.user == "vagrant") assert(node2.account.ssh_args.strip() == "-o 'HostName 127.0.0.2' -o 'Port 2200' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker2/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'") assert(node2.account.ssh_hostname == '127.0.0.2')
def check_one_host_parsing(self, monkeypatch): """check the behavior of VagrantCluster when cluster_file is not specified. VagrantCluster should read cluster information from _vagrant_ssh_config(). """ self._set_monkeypatch_attr(monkeypatch) cluster = VagrantCluster() assert len(cluster) == 2 assert cluster.num_available_nodes() == 2 node1, node2 = cluster.request(2) assert node1.account.hostname == "worker1" assert node1.account.user == "vagrant" assert node1.account.ssh_args.strip() == "-o 'HostName 127.0.0.1' -o 'Port 2222' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker1/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'" assert node1.account.ssh_hostname == '127.0.0.1' assert node2.account.hostname == "worker2" assert node2.account.user == "vagrant" assert node2.account.ssh_args.strip() == "-o 'HostName 127.0.0.2' -o 'Port 2200' -o 'UserKnownHostsFile /dev/null' -o 'StrictHostKeyChecking no' -o 'PasswordAuthentication no' -o 'IdentityFile /Users/foo/ducktape.git/.vagrant/machines/worker2/virtualbox/private_key' -o 'IdentitiesOnly yes' -o 'LogLevel FATAL'" assert node2.account.ssh_hostname == '127.0.0.2'
def check_no_valid_network_devices(self, monkeypatch): """ test to make sure that a remote account error is raised when no network devices are found """ monkeypatch.setattr( "ducktape.cluster.vagrant.VagrantCluster._vagrant_ssh_config", lambda vc: (TWO_HOSTS, None)) monkeypatch.setattr( "ducktape.cluster.linux_remoteaccount.LinuxRemoteAccount.get_network_devices", lambda account: []) with pytest.raises(RemoteAccountError): VagrantCluster()
def check_cluster_file_write(self, monkeypatch): """check the behavior of VagrantCluster when cluster_file is specified but the file doesn't exist. VagrantCluster should read cluster information from _vagrant_ssh_config() and write the information to cluster_file. """ self._set_monkeypatch_attr(monkeypatch) assert not os.path.exists(self.cluster_file) cluster = VagrantCluster(cluster_file=self.cluster_file) cluster_json_expected = {} nodes = [{"hostname": node_account.hostname, "ssh_hostname": node_account.ssh_hostname, "user": node_account.user, "ssh_args": node_account.ssh_args, "externally_routable_ip": node_account.externally_routable_ip} for node_account in cluster.available_nodes] cluster_json_expected["nodes"] = nodes cluster_json_actual = json.load(open(os.path.abspath(self.cluster_file))) os.remove(self.cluster_file) assert cluster_json_actual == cluster_json_expected
def check_pickleable(self, monkeypatch): self._set_monkeypatch_attr(monkeypatch) cluster = VagrantCluster(is_type_based=False) pickle.dumps(cluster)
def check_pickleable(self, monkeypatch): self._set_monkeypatch_attr(monkeypatch) cluster = VagrantCluster() pickle.dumps(cluster)
def make_vagrant_cluster(*args, **kwargs): return VagrantCluster(make_remote_account_func=create_fake_remote_account, *args, **kwargs)