Example #1
0
    def test_read_write_fan_speed_rack2_board1(self):
        """SNMP read of fan speed. Happy case. Read, write, set back to the original.
        This is a lot like test_read_write_fan_speed_rack1_board0, but verifies that
        command routing is going to the correct emulator.
        NOTE: If a write fails or the write back to original fails, this test may be
        non-reentrant. To avoid reentrancy issues, no other tests should run against
        this device at /rack_2/60000001/0004.
        """
        logger.debug('test_read_write_fan_speed_rack2_board1')
        base_uri = Uri.create(_S.URI_FAN, RACK_2, BOARD_60000001, '0004')
        response = http.get(base_uri).json()
        logger.debug(json.dumps(response, sort_keys=True, indent=4, separators=(',', ': ')))
        self._verify_read_fan_response(response, _S.OK, [], 21)

        response = http.get(Uri.append(base_uri, '300')).json()
        logger.debug(json.dumps(response, sort_keys=True, indent=4, separators=(',', ': ')))
        self._verify_read_fan_response(response, _S.OK, [], 300)

        logger.debug('second read')
        response = http.get(base_uri).json()
        self._verify_read_fan_response(response, _S.OK, [], 300)

        logger.debug('second write (to initial)')
        response = http.get(Uri.append(base_uri, '21')).json()
        self._verify_read_fan_response(response, _S.OK, [], 21)

        logger.debug('third read')
        response = http.get(base_uri).json()
        self._verify_read_fan_response(response, _S.OK, [], 21)
    def test_read_write_power_rack2_board1(self):
        """SNMP read/write of power. Happy case. Simulates an SNMP PDU.
        Read, off, read, on, read, cycle, read, off, read.
        This is a lot like test_read_write_power_rack2_board1, but verifies that
        command routing is going to the correct emulator.
        Also here the initial power state is off.
        NOTE: If a write fails or the write back to original fails, this test may be
        non-reentrant. To avoid reentrancy issues, no other tests should run against
        this device at /rack_2/60000001/0012.
        """
        logger.debug('test_read_write_power_rack2_board1')
        base_uri = Uri.create(_S.URI_POWER, RACK_2, BOARD_60000000, '0012')
        response = http.get(base_uri).json()
        logger.debug(
            json.dumps(response,
                       sort_keys=True,
                       indent=4,
                       separators=(',', ': ')))
        self._verify_power_response(response, 26, False, True, _S.OFF)

        logger.debug('set power off')
        response = http.get(Uri.append(base_uri, _S.OFF)).json()
        logger.debug(
            json.dumps(response,
                       sort_keys=True,
                       indent=4,
                       separators=(',', ': ')))
        self._verify_power_response(response, 26, False, True, _S.OFF)

        logger.debug('second read')
        response = http.get(base_uri).json()
        self._verify_power_response(response, 26, False, True, _S.OFF)

        logger.debug('set power on')
        response = http.get(Uri.append(base_uri, _S.ON)).json()
        self._verify_power_response(response, 26, False, True, _S.ON)

        logger.debug('third read')
        response = http.get(base_uri).json()
        self._verify_power_response(response, 26, False, True, _S.ON)

        logger.debug('set power cycle')
        response = http.get(Uri.append(base_uri, _S.CYCLE)).json()
        self._verify_power_response(response, 26, False, True, _S.ON)

        logger.debug('fourth read')
        response = http.get(base_uri).json()
        self._verify_power_response(response, 26, False, True, _S.ON)

        logger.debug('set power off')
        response = http.get(Uri.append(base_uri, _S.OFF)).json()
        self._verify_power_response(response, 26, False, True, _S.OFF)

        logger.debug('fifth read')
        response = http.get(base_uri).json()
        self._verify_power_response(response, 26, False, True, _S.OFF)
Example #3
0
 def test_scan_by_rack1(self):
     """ Test scan rack_1 expecting sad results. Emulator is down."""
     try:
         http.get(Uri.create(_S.URI_SCAN, RACK_1))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_RACK_FOUND_WITH_ID.format(RACK_1))
Example #4
0
    def setUpClass(cls):
        """Verify which emulators are up and down when the test cases start."""
        logger.debug('Starting SnmpDeviceKillsTestCase.')
        logger.debug('Verify containers are either alive or killed.')

        cli = docker.Client(base_url='unix://var/run/docker.sock')

        # Kill one of the containers.
        cli.kill(SNMP_EMULATOR_SYNSE_TESTDEVICE1_BOARD1)

        # now, we get the running containers to verify
        running = cli.containers(filters={'status': 'running'})

        alive = []
        for ctr in running:
            if 'Labels' in ctr:
                for k, v in ctr['Labels'].iteritems():
                    if k == 'com.docker.compose.service':
                        alive.append(v)

        # verify that the board we expect to be running is running, and the
        # one we expect to be down is not running.
        assert SNMP_EMULATOR_SYNSE_TESTDEVICE1_BOARD1 not in alive, 'Container alive, but should be dead.'
        assert SNMP_EMULATOR_SYNSE_TESTDEVICE1_BOARD2 in alive, 'Container dead, but should be alive.'

        logger.debug('Forcing scan.')
        r = http.get(Uri.create(_S.URI_SCAN_FORCE), timeout=30)
        assert http.request_ok(r.status_code), 'Checking scan status code {}'.format(r.status_code)

        response = r.json()
        logger.debug(json.dumps(response, sort_keys=True, indent=4, separators=(',', ': ')))
 def test_power_read_rack2_not_supported(self):
     """Sad case power read on the second rack. Power command on a fan."""
     try:
         http.get(Uri.create(_S.URI_POWER, RACK_2, BOARD_60000001, '0002'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_POWER_COMMAND_NOT_SUPPORTED)
Example #6
0
 def test_read_voltage_rack1(self):
     """SNMP read of voltage variable. Sad case. Emulator is dead."""
     logger.debug('test_read_voltage')
     try:
         http.get(Uri.read_voltage(RACK_1, BOARD_60000000, '0004'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #7
0
 def test_version_board_does_not_exist_rack2(self):
     """SNMP version testing. Board does not exist. Sad case."""
     try:
         http.get(Uri.create(_S.URI_VERSION, RACK_2, BOARD_60000002))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(
             e, 500, _S.ERROR_NO_REGISTERED_DEVICE_FOR_BOARD.format(int(BOARD_60000002, 16)))
Example #8
0
 def test_version_rack1(self):
     """SNMP version testing. Sad case. Emulator is down and we did a scan
      all force which means board 60000000 is unknown to Synse."""
     try:
         http.get(Uri.create(_S.URI_VERSION, RACK_1, BOARD_60000000))
     except VaporHTTPError as e:
         self._verify_vapor_http_error(
             e, 500, _S.ERROR_NO_BOARD_ON_RACK.format(RACK_1, BOARD_60000000))
Example #9
0
 def test_scan_by_rack_does_not_exist(self):
     """ Test scan rack_965 that does not exist.
     """
     try:
         http.get(Uri.create(_S.URI_SCAN, 'rack_965'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_RACK_FOUND_WITH_ID.format('rack_965'))
 def test_write_power_rack2_board0_device_does_not_exist(self):
     """SNMP read of power. Sad case. Power command on non-existent device."""
     logger.debug('test_write_fan_speed_rack2_board0_wrong_device_type')
     try:
         http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, 'f001', '300'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_DEVICE_WITH_ID.format('f001'))
 def test_write_power_rack1_board0_wrong_device_type(self):
     """SNMP read of power. Sad case. Power command on LED."""
     try:
         http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '000c', '300'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(
             e, 500, _S.ERROR_POWER_COMMAND_NOT_SUPPORTED)
 def test_power_read_rack1_bad(self):
     """Sad case power read on the first rack. Emulator is dead."""
     logger.debug('test_power_read_rack1')
     try:
         http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '0011'), timeout=7)
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.SNMP_EMULATOR_DOWN)
 def test_power_read_rack1(self):
     logger.debug('test_power_read_rack1 (emulator was killed)')
     base_uri = Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '0002')
     try:
         http.get(base_uri, timeout=7)
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_POWER_COMMAND_NOT_SUPPORTED)
 def test_write_fan_speed_rack1_board0_wrong_device_type(self):
     """SNMP write of fan speed. Sad case. Fan control on LED."""
     logger.debug('test_write_fan_speed_rack1_board0_wrong_device_type')
     try:
         http.get(Uri.create(_S.URI_FAN, RACK_1, BOARD_60000000, '000c', '300'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_FAN_COMMAND_NOT_SUPPORTED)
 def test_read_fan_speed_rack1_board0_down(self):
     """SNMP read of fan speed. Sad case. Emulator is down."""
     logger.debug('test_read_fan_speed_rack1_board0')
     try:
         http.get(Uri.read_fan_speed(RACK_1, BOARD_60000000, '0000'), timeout=7)
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.SNMP_EMULATOR_DOWN)
Example #16
0
    def test_read_device_does_not_exist_rack1(self):
        """Test read where device does not exist. Sad case."""
        try:
            http.get(Uri.read_temperature(RACK_1, BOARD_60000000, 'F001'))
            self.fail(EXPECTED_VAPOR_HTTP_ERROR)

        except VaporHTTPError as e:
            self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
 def test_write_led_rack1_board0_wrong_device_type(self):
     """SNMP write of LED Sad case. LED command on LED."""
     try:
         http.get(Uri.create(_S.URI_LED, RACK_1, BOARD_60000000, '0016', _S.ON))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(
             e, 500, _S.ERROR_LED_COMMAND_NOT_SUPPORTED)
Example #18
0
 def test_read_fan_speed_rack1_down(self):
     """SNMP read of fan speed. Sad case. Emulator is down."""
     logger.debug('test_read_fan_speed_rack2')
     try:
         http.get(Uri.read_fan_speed(RACK_1, BOARD_60000000, '0000'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
 def test_write_led_rack1_board0_device_does_not_exist(self):
     """SNMP read of fan speed. Sad case. Fan control on non-existent device."""
     logger.debug('test_write_led_rack1_board0_device_does_not_exist')
     try:
         http.get(Uri.create(_S.URI_LED, RACK_1, BOARD_60000000, 'f071', _S.ON))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_DEVICE_WITH_ID.format('f071'))
Example #20
0
 def test_write_led_rack1_board0_wrong_device_type(self):
     """SNMP write of LED Sad case. LED command on LED. Emulator is down."""
     try:
         http.get(Uri.create(_S.URI_LED, RACK_1, BOARD_60000000, '0016', _S.ON))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(
             e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #21
0
    def test_read_board_does_not_exist_rack1(self):
        """Test read where board does not exist. Sad case."""
        try:
            http.get(Uri.read_temperature(RACK_1, '60000006', '0001'))
            self.fail(EXPECTED_VAPOR_HTTP_ERROR)

        except VaporHTTPError as e:
            self._verify_vapor_http_error(e, 500, _S.ERROR_NO_REGISTERED_DEVICE_FOR_BOARD.format(int('60000006', 16)))
Example #22
0
 def test_power_read_rack1_down(self):
     """Sad case power read on the first rack. Emulator is dead."""
     logger.debug('test_power_read_rack1')
     try:
         http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '0011'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #23
0
 def test_power_read_rack1_not_supported(self):
     """Sad case power read on the first rack. Power command on a fan.
     Emulator is down."""
     try:
         http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '0002'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #24
0
    def test_power_device_does_not_exist_rack1(self):
        """Test power where device does not exist. Sad case."""
        try:
            http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, 'F001'))
            self.fail(EXPECTED_VAPOR_HTTP_ERROR)

        except VaporHTTPError as e:
            self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #25
0
    def test_power_board_does_not_exist_rack1(self):
        """Test power where board does not exist. Sad case."""
        try:
            http.get(Uri.create(_S.URI_POWER, RACK_1, '60000006', '0002'))
            self.fail(EXPECTED_VAPOR_HTTP_ERROR)

        except VaporHTTPError as e:
            self._verify_vapor_http_error(e, 500, _S.ERROR_NO_REGISTERED_DEVICE_FOR_BOARD.format(int('60000006', 16)))
Example #26
0
 def test_power_read_rack1(self):
     logger.debug('test_power_read_rack1 (emulator was killed)')
     base_uri = Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '0002')
     try:
         http.get(base_uri)
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #27
0
 def test_read_write_led_rack1_board0(self):
     """SNMP read/write of LED. Sad case. Emulator is down."""
     logger.debug('test_read_write_led_rack1_board0')
     base_uri = Uri.create(_S.URI_LED, RACK_1, BOARD_60000000, '000d')
     try:
         http.get(base_uri)
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #28
0
    def test_read_wrong_device_type_in_url_rack1(self):
        """Read a valid device, but wrong type in the url. Read voltage, but
        it's a temperature sensor. Sad case. Emulator is down."""
        try:
            http.get(Uri.read_voltage(RACK_1, BOARD_60000000, '0001'))
            self.fail(EXPECTED_VAPOR_HTTP_ERROR)

        except VaporHTTPError as e:
            self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #29
0
    def test_power_write_rack1(self):
        """Test power write where the underlying device does not support it.
        Sad case. Emulator is down."""
        try:
            http.get(Uri.create(_S.URI_POWER, RACK_1, BOARD_60000000, '0002', _S.ON))
            self.fail(EXPECTED_VAPOR_HTTP_ERROR)

        except VaporHTTPError as e:
            self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))
Example #30
0
 def test_write_fan_speed_rack1_board0_device_does_not_exist(self):
     """SNMP read of fan speed. Sad case. Fan control on non-existent
     device. Emulator is down."""
     logger.debug('test_write_fan_speed_rack1_board0_wrong_device_type')
     try:
         http.get(Uri.create(_S.URI_FAN, RACK_1, BOARD_60000000, 'f001', '300'))
         self.fail(EXPECTED_VAPOR_HTTP_ERROR)
     except VaporHTTPError as e:
         self._verify_vapor_http_error(e, 500, _S.ERROR_NO_BOARD_WITH_ID.format(BOARD_60000000))