def test_connect_juju_client(self): with patch.object(utils, 'get_juju_major_version', return_value=2): with patch('jujuclient.juju2.environment.Environment', autospec=True) as jc_mock: jc_mock.connect.return_value = 'bar' env = connect_juju_client('foo', 1) jc_mock.connect.assert_called_once() self.assertEqual(env, 'bar')
def test_connect_juju_client_socket_timeout(self): with patch.object(utils, 'get_juju_major_version', return_value=2): with patch('jujuclient.juju2.environment.Environment', autospec=True) as jc_mock: jc_mock.connect.side_effect = socket.timeout env = connect_juju_client('foo', 2) self.assertEqual(jc_mock.connect.mock_calls, [call(env_name='foo'), call(env_name='foo')]) self.assertEqual(env, None)
def test_connect_juju_client_socket_timeout(self): with patch.object(utils, 'get_juju_major_version', return_value=2): with patch('jujuclient.juju2.environment.Environment', autospec=True) as jc_mock: jc_mock.connect.side_effect = socket.timeout env = connect_juju_client('foo', 2) self.assertEqual( jc_mock.connect.mock_calls, [call(env_name='foo'), call(env_name='foo')]) self.assertEqual(env, None)
def run_plan(self, test_plan): env = connect_juju_client(self.controller, logging=logging) if not env: msg = "Jujuclient could not connect to {} ".format(self.controller) logging.error(msg) test_result = self.generate_test_result( provider=get_provider_name(guess_provider_name( self.controller)), test_name="Juju client failed", output=msg) self.save_result_in_datastore(test_result, [], test_plan) return False env.name = self.controller env_info = env.info() provider = (env_info.get("provider-type") or env_info.get("ProviderType")) env.provider_name = get_provider_name(provider) logging.info('Running test on {}.'.format(env.provider_name)) resource_available = self.check_cloud_resource(test_plan, env_info) if resource_available is False: msg = 'Resource not available' logging.error(msg) test_result = self.generate_test_result(provider=env.provider_name, test_name=msg, output=msg) self.save_result_in_datastore(test_result, [], test_plan) return False benchmark_result = [] try: test_result = self.run_tests(test_plan, env) benchmark_result = self.run_benchmarks(test_plan, env) except Exception: tb = traceback.format_exc() error = "Exception ({}):\n{}".format(env.name, tb) logging.error(error) # create a fake SuiteResult to hold exception traceback test_result = self.generate_test_result(provider=env.provider_name, test_name='Exception', output=error) self.save_result_in_datastore(test_result, benchmark_result, test_plan) return test_result.test_outcome == "PASS"
def run_plan(self, test_plan): env = connect_juju_client(self.controller, logging=logging) if not env: logging.error("Jujuclient could not connect to {} ".format( self.controller)) return False env.name = self.controller provider = (env.info().get("provider-type") or env.info().get("ProviderType")) env.provider_name = get_provider_name(provider) logging.info('Running test on {}.'.format(env.provider_name)) try: test_result = self.run_tests(test_plan, env) benchmark_results = self.run_benchmarks(test_plan, env) except Exception: tb = traceback.format_exc() error = "Exception ({}):\n{}".format(env.name, tb) logging.error(error) # create a fake SuiteResult to hold exception traceback test_result = model.SuiteResult( provider=env.provider_name, test_outcome='Error Running Tests', tests=[model.TestResult( name='Error Running Tests', duration=0.0, output=error, result='INFRA', )]) return False datastore = DataStore.get( self.args.results_dir, self.args.bucket, self.args.s3_creds, self.args.s3_public) svg_data = fetch_svg(test_result.bundle_yaml) with datastore.lock(): index = self.load_index(datastore) report = self.load_report(datastore, index, test_plan) report.upsert_result(test_result) report.upsert_benchmarks(benchmark_results) index.upsert_report(report) datastore.write( 'css/base.css', resource_string(__name__, 'static/css/base.css').decode('utf8')) datastore.write( 'css/vanilla.min.css', resource_string(__name__, 'static/css/vanilla.min.css').decode('utf8')) datastore.write(index.full_index_filename_json, index.as_json()) datastore.write(index.full_index_filename_html, index.as_html()) datastore.write(report.filename_json, report.as_json()) datastore.write(report.filename_html, report.as_html(svg_data)) datastore.write(index.summary_filename_html, index.summary_html()) datastore.write(index.summary_filename_json, index.summary_json()) for bundle_name in index.bundle_names(): datastore.write( index.bundle_index_html(bundle_name), index.as_html(bundle_name, limit=self.args.results_per_bundle)) datastore.write( index.bundle_index_json(bundle_name), index.as_json(bundle_name, limit=self.args.results_per_bundle)) return True