Home | History | Annotate | Download | only in client_lib
      1 # Copyright 2015 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """Module contains a simple client lib to control failures."""
      6 
      7 import json
      8 import urllib2
      9 
     10 import common
     11 from fake_device_server.client_lib import common_client
     12 from fake_device_server import fail_control
     13 
     14 
     15 class FailControlClient(common_client.CommonClient):
     16     """Client library for control failing."""
     17 
     18     def __init__(self, *args, **kwargs):
     19         common_client.CommonClient.__init__(
     20                 self, fail_control.FAIL_CONTROL_PATH, *args, **kwargs)
     21 
     22 
     23     def start_failing_requests(self):
     24         """Starts failing request."""
     25         headers = self.add_auth_headers({'Content-Type': 'application/json'})
     26         request = urllib2.Request(self.get_url(['start_failing_requests']),
     27                                   json.dumps(dict()), headers=headers)
     28         url_h = urllib2.urlopen(request)
     29         return json.loads(url_h.read())
     30 
     31 
     32     def stop_failing_requests(self):
     33         """Stops failing request."""
     34         headers = self.add_auth_headers({'Content-Type': 'application/json'})
     35         request = urllib2.Request(self.get_url(['stop_failing_requests']),
     36                                   json.dumps(dict()), headers=headers)
     37         url_h = urllib2.urlopen(request)
     38         return json.loads(url_h.read())
     39