How to use uptime method in autotest

Best Python code snippet using autotest_python

uptime_service_pb2_grpc.py

Source:uptime_service_pb2_grpc.py Github

copy

Full Screen

1# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!2import grpc3from google.cloud.monitoring_v3.proto import (4 uptime_pb2 as google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2,5)6from google.cloud.monitoring_v3.proto import (7 uptime_service_pb2 as google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2,8)9from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb210class UptimeCheckServiceStub(object):11 """The UptimeCheckService API is used to manage (list, create, delete, edit)12 uptime check configurations in the Stackdriver Monitoring product. An uptime13 check is a piece of configuration that determines which resources and14 services to monitor for availability. These configurations can also be15 configured interactively by navigating to the [Cloud Console]16 (http://console.cloud.google.com), selecting the appropriate project,17 clicking on "Monitoring" on the left-hand side to navigate to Stackdriver,18 and then clicking on "Uptime".19 """20 def __init__(self, channel):21 """Constructor.22 Args:23 channel: A grpc.Channel.24 """25 self.ListUptimeCheckConfigs = channel.unary_unary(26 "/google.monitoring.v3.UptimeCheckService/ListUptimeCheckConfigs",27 request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckConfigsRequest.SerializeToString,28 response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckConfigsResponse.FromString,29 )30 self.GetUptimeCheckConfig = channel.unary_unary(31 "/google.monitoring.v3.UptimeCheckService/GetUptimeCheckConfig",32 request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.GetUptimeCheckConfigRequest.SerializeToString,33 response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2.UptimeCheckConfig.FromString,34 )35 self.CreateUptimeCheckConfig = channel.unary_unary(36 "/google.monitoring.v3.UptimeCheckService/CreateUptimeCheckConfig",37 request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.CreateUptimeCheckConfigRequest.SerializeToString,38 response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2.UptimeCheckConfig.FromString,39 )40 self.UpdateUptimeCheckConfig = channel.unary_unary(41 "/google.monitoring.v3.UptimeCheckService/UpdateUptimeCheckConfig",42 request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.UpdateUptimeCheckConfigRequest.SerializeToString,43 response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2.UptimeCheckConfig.FromString,44 )45 self.DeleteUptimeCheckConfig = channel.unary_unary(46 "/google.monitoring.v3.UptimeCheckService/DeleteUptimeCheckConfig",47 request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.DeleteUptimeCheckConfigRequest.SerializeToString,48 response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,49 )50 self.ListUptimeCheckIps = channel.unary_unary(51 "/google.monitoring.v3.UptimeCheckService/ListUptimeCheckIps",52 request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckIpsRequest.SerializeToString,53 response_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckIpsResponse.FromString,54 )55class UptimeCheckServiceServicer(object):56 """The UptimeCheckService API is used to manage (list, create, delete, edit)57 uptime check configurations in the Stackdriver Monitoring product. An uptime58 check is a piece of configuration that determines which resources and59 services to monitor for availability. These configurations can also be60 configured interactively by navigating to the [Cloud Console]61 (http://console.cloud.google.com), selecting the appropriate project,62 clicking on "Monitoring" on the left-hand side to navigate to Stackdriver,63 and then clicking on "Uptime".64 """65 def ListUptimeCheckConfigs(self, request, context):66 """Lists the existing valid uptime check configurations for the project,67 leaving out any invalid configurations.68 """69 context.set_code(grpc.StatusCode.UNIMPLEMENTED)70 context.set_details("Method not implemented!")71 raise NotImplementedError("Method not implemented!")72 def GetUptimeCheckConfig(self, request, context):73 """Gets a single uptime check configuration.74 """75 context.set_code(grpc.StatusCode.UNIMPLEMENTED)76 context.set_details("Method not implemented!")77 raise NotImplementedError("Method not implemented!")78 def CreateUptimeCheckConfig(self, request, context):79 """Creates a new uptime check configuration.80 """81 context.set_code(grpc.StatusCode.UNIMPLEMENTED)82 context.set_details("Method not implemented!")83 raise NotImplementedError("Method not implemented!")84 def UpdateUptimeCheckConfig(self, request, context):85 """Updates an uptime check configuration. You can either replace the entire86 configuration with a new one or replace only certain fields in the current87 configuration by specifying the fields to be updated via `"updateMask"`.88 Returns the updated configuration.89 """90 context.set_code(grpc.StatusCode.UNIMPLEMENTED)91 context.set_details("Method not implemented!")92 raise NotImplementedError("Method not implemented!")93 def DeleteUptimeCheckConfig(self, request, context):94 """Deletes an uptime check configuration. Note that this method will fail95 if the uptime check configuration is referenced by an alert policy or96 other dependent configs that would be rendered invalid by the deletion.97 """98 context.set_code(grpc.StatusCode.UNIMPLEMENTED)99 context.set_details("Method not implemented!")100 raise NotImplementedError("Method not implemented!")101 def ListUptimeCheckIps(self, request, context):102 """Returns the list of IPs that checkers run from103 """104 context.set_code(grpc.StatusCode.UNIMPLEMENTED)105 context.set_details("Method not implemented!")106 raise NotImplementedError("Method not implemented!")107def add_UptimeCheckServiceServicer_to_server(servicer, server):108 rpc_method_handlers = {109 "ListUptimeCheckConfigs": grpc.unary_unary_rpc_method_handler(110 servicer.ListUptimeCheckConfigs,111 request_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckConfigsRequest.FromString,112 response_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckConfigsResponse.SerializeToString,113 ),114 "GetUptimeCheckConfig": grpc.unary_unary_rpc_method_handler(115 servicer.GetUptimeCheckConfig,116 request_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.GetUptimeCheckConfigRequest.FromString,117 response_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2.UptimeCheckConfig.SerializeToString,118 ),119 "CreateUptimeCheckConfig": grpc.unary_unary_rpc_method_handler(120 servicer.CreateUptimeCheckConfig,121 request_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.CreateUptimeCheckConfigRequest.FromString,122 response_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2.UptimeCheckConfig.SerializeToString,123 ),124 "UpdateUptimeCheckConfig": grpc.unary_unary_rpc_method_handler(125 servicer.UpdateUptimeCheckConfig,126 request_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.UpdateUptimeCheckConfigRequest.FromString,127 response_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__pb2.UptimeCheckConfig.SerializeToString,128 ),129 "DeleteUptimeCheckConfig": grpc.unary_unary_rpc_method_handler(130 servicer.DeleteUptimeCheckConfig,131 request_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.DeleteUptimeCheckConfigRequest.FromString,132 response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,133 ),134 "ListUptimeCheckIps": grpc.unary_unary_rpc_method_handler(135 servicer.ListUptimeCheckIps,136 request_deserializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckIpsRequest.FromString,137 response_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_uptime__service__pb2.ListUptimeCheckIpsResponse.SerializeToString,138 ),139 }140 generic_handler = grpc.method_handlers_generic_handler(141 "google.monitoring.v3.UptimeCheckService", rpc_method_handlers142 )...

Full Screen

Full Screen

snippets.py

Source:snippets.py Github

copy

Full Screen

1# Copyright 2018 Google LLC2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14from __future__ import print_function15import argparse16import os17import pprint18from google.cloud import monitoring_v319import tabulate20# [START monitoring_uptime_check_create]21def create_uptime_check_config(project_name, host_name=None,22 display_name=None):23 config = monitoring_v3.types.uptime_pb2.UptimeCheckConfig()24 config.display_name = display_name or 'New uptime check'25 config.monitored_resource.type = 'uptime_url'26 config.monitored_resource.labels.update(27 {'host': host_name or 'example.com'})28 config.http_check.path = '/'29 config.http_check.port = 8030 config.timeout.seconds = 1031 config.period.seconds = 30032 client = monitoring_v3.UptimeCheckServiceClient()33 new_config = client.create_uptime_check_config(project_name, config)34 pprint.pprint(new_config)35 return new_config36# [END monitoring_uptime_check_create]37# [START monitoring_uptime_check_update]38def update_uptime_check_config(config_name, new_display_name=None,39 new_http_check_path=None):40 client = monitoring_v3.UptimeCheckServiceClient()41 config = client.get_uptime_check_config(config_name)42 field_mask = monitoring_v3.types.FieldMask()43 if new_display_name:44 field_mask.paths.append('display_name')45 config.display_name = new_display_name46 if new_http_check_path:47 field_mask.paths.append('http_check.path')48 config.http_check.path = new_http_check_path49 client.update_uptime_check_config(config, field_mask)50# [END monitoring_uptime_check_update]51# [START monitoring_uptime_check_list_configs]52def list_uptime_check_configs(project_name):53 client = monitoring_v3.UptimeCheckServiceClient()54 configs = client.list_uptime_check_configs(project_name)55 for config in configs:56 pprint.pprint(config)57# [END monitoring_uptime_check_list_configs]58# [START monitoring_uptime_check_list_ips]59def list_uptime_check_ips():60 client = monitoring_v3.UptimeCheckServiceClient()61 ips = client.list_uptime_check_ips()62 print(tabulate.tabulate(63 [(ip.region, ip.location, ip.ip_address) for ip in ips],64 ('region', 'location', 'ip_address')65 ))66# [END monitoring_uptime_check_list_ips]67# [START monitoring_uptime_check_get]68def get_uptime_check_config(config_name):69 client = monitoring_v3.UptimeCheckServiceClient()70 config = client.get_uptime_check_config(config_name)71 pprint.pprint(config)72# [END monitoring_uptime_check_get]73# [START monitoring_uptime_check_delete]74def delete_uptime_check_config(config_name):75 client = monitoring_v3.UptimeCheckServiceClient()76 client.delete_uptime_check_config(config_name)77 print('Deleted ', config_name)78# [END monitoring_uptime_check_delete]79class MissingProjectIdError(Exception):80 pass81def project_id():82 """Retreieves the project id from the environment variable.83 Raises:84 MissingProjectIdError -- When not set.85 Returns:86 str -- the project name87 """88 project_id = os.environ['GCLOUD_PROJECT']89 if not project_id:90 raise MissingProjectIdError(91 'Set the environment variable ' +92 'GCLOUD_PROJECT to your Google Cloud Project Id.')93 return project_id94def project_name():95 return 'projects/' + project_id()96if __name__ == '__main__':97 parser = argparse.ArgumentParser(98 description='Demonstrates Uptime Check API operations.')99 subparsers = parser.add_subparsers(dest='command')100 list_uptime_check_configs_parser = subparsers.add_parser(101 'list-uptime-check-configs',102 help=list_uptime_check_configs.__doc__103 )104 list_uptime_check_ips_parser = subparsers.add_parser(105 'list-uptime-check-ips',106 help=list_uptime_check_ips.__doc__107 )108 create_uptime_check_config_parser = subparsers.add_parser(109 'create-uptime-check',110 help=create_uptime_check_config.__doc__111 )112 create_uptime_check_config_parser.add_argument(113 '-d', '--display_name',114 required=False,115 )116 create_uptime_check_config_parser.add_argument(117 '-o', '--host_name',118 required=False,119 )120 get_uptime_check_config_parser = subparsers.add_parser(121 'get-uptime-check-config',122 help=get_uptime_check_config.__doc__123 )124 get_uptime_check_config_parser.add_argument(125 '-m', '--name',126 required=True,127 )128 delete_uptime_check_config_parser = subparsers.add_parser(129 'delete-uptime-check-config',130 help=delete_uptime_check_config.__doc__131 )132 delete_uptime_check_config_parser.add_argument(133 '-m', '--name',134 required=True,135 )136 update_uptime_check_config_parser = subparsers.add_parser(137 'update-uptime-check-config',138 help=update_uptime_check_config.__doc__139 )140 update_uptime_check_config_parser.add_argument(141 '-m', '--name',142 required=True,143 )144 update_uptime_check_config_parser.add_argument(145 '-d', '--display_name',146 required=False,147 )148 update_uptime_check_config_parser.add_argument(149 '-p', '--uptime_check_path',150 required=False,151 )152 args = parser.parse_args()153 if args.command == 'list-uptime-check-configs':154 list_uptime_check_configs(project_name())155 elif args.command == 'list-uptime-check-ips':156 list_uptime_check_ips()157 elif args.command == 'create-uptime-check':158 create_uptime_check_config(project_name(), args.host_name,159 args.display_name)160 elif args.command == 'get-uptime-check-config':161 get_uptime_check_config(args.name)162 elif args.command == 'delete-uptime-check-config':163 delete_uptime_check_config(args.name)164 elif args.command == 'update-uptime-check-config':165 if not args.display_name and not args.uptime_check_path:166 print('Nothing to update. Pass --display_name or '167 '--uptime_check_path.')168 else:169 update_uptime_check_config(args.name, args.display_name,...

Full Screen

Full Screen

test_uptime.py

Source:test_uptime.py Github

copy

Full Screen

1"""The tests for the uptime sensor platform."""2import unittest3from unittest.mock import patch4from datetime import timedelta5from homeassistant.util.async_ import run_coroutine_threadsafe6from homeassistant.setup import setup_component7from homeassistant.components.sensor.uptime import UptimeSensor8from tests.common import get_test_home_assistant9class TestUptimeSensor(unittest.TestCase):10 """Test the uptime sensor."""11 def setUp(self):12 """Set up things to run when tests begin."""13 self.hass = get_test_home_assistant()14 def tearDown(self):15 """Stop everything that was started."""16 self.hass.stop()17 def test_uptime_min_config(self):18 """Test minimum uptime configuration."""19 config = {20 'sensor': {21 'platform': 'uptime',22 }23 }24 assert setup_component(self.hass, 'sensor', config)25 def test_uptime_sensor_name_change(self):26 """Test uptime sensor with different name."""27 config = {28 'sensor': {29 'platform': 'uptime',30 'name': 'foobar',31 }32 }33 assert setup_component(self.hass, 'sensor', config)34 def test_uptime_sensor_config_hours(self):35 """Test uptime sensor with hours defined in config."""36 config = {37 'sensor': {38 'platform': 'uptime',39 'unit_of_measurement': 'hours',40 }41 }42 assert setup_component(self.hass, 'sensor', config)43 def test_uptime_sensor_config_minutes(self):44 """Test uptime sensor with minutes defined in config."""45 config = {46 'sensor': {47 'platform': 'uptime',48 'unit_of_measurement': 'minutes',49 }50 }51 assert setup_component(self.hass, 'sensor', config)52 def test_uptime_sensor_days_output(self):53 """Test uptime sensor output data."""54 sensor = UptimeSensor('test', 'days')55 assert sensor.unit_of_measurement == 'days'56 new_time = sensor.initial + timedelta(days=1)57 with patch('homeassistant.util.dt.now', return_value=new_time):58 run_coroutine_threadsafe(59 sensor.async_update(),60 self.hass.loop61 ).result()62 assert sensor.state == 1.0063 new_time = sensor.initial + timedelta(days=111.499)64 with patch('homeassistant.util.dt.now', return_value=new_time):65 run_coroutine_threadsafe(66 sensor.async_update(),67 self.hass.loop68 ).result()69 assert sensor.state == 111.5070 def test_uptime_sensor_hours_output(self):71 """Test uptime sensor output data."""72 sensor = UptimeSensor('test', 'hours')73 assert sensor.unit_of_measurement == 'hours'74 new_time = sensor.initial + timedelta(hours=16)75 with patch('homeassistant.util.dt.now', return_value=new_time):76 run_coroutine_threadsafe(77 sensor.async_update(),78 self.hass.loop79 ).result()80 assert sensor.state == 16.0081 new_time = sensor.initial + timedelta(hours=72.499)82 with patch('homeassistant.util.dt.now', return_value=new_time):83 run_coroutine_threadsafe(84 sensor.async_update(),85 self.hass.loop86 ).result()87 assert sensor.state == 72.5088 def test_uptime_sensor_minutes_output(self):89 """Test uptime sensor output data."""90 sensor = UptimeSensor('test', 'minutes')91 assert sensor.unit_of_measurement == 'minutes'92 new_time = sensor.initial + timedelta(minutes=16)93 with patch('homeassistant.util.dt.now', return_value=new_time):94 run_coroutine_threadsafe(95 sensor.async_update(),96 self.hass.loop97 ).result()98 assert sensor.state == 16.0099 new_time = sensor.initial + timedelta(minutes=12.499)100 with patch('homeassistant.util.dt.now', return_value=new_time):101 run_coroutine_threadsafe(102 sensor.async_update(),103 self.hass.loop104 ).result()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful