コード例 #1
0
def test_sensorkit_from_type(cb):
    """Test creation code for SensorKit and make sure data slots in correctly."""
    skit = SensorKit.from_type(cb, 'LINUX', '64', 'SUSE', '1.2.3.4')
    assert skit.sensor_type == {
        'device_type': 'LINUX',
        'architecture': '64',
        'type': 'SUSE',
        'version': '1.2.3.4'
    }
    assert skit.sensor_type['architecture'] == '64'
    assert skit.sensor_type['type'] == 'SUSE'
    assert skit.sensor_type['version'] == '1.2.3.4'
    skit2 = SensorKit(
        cb, {
            'sensor_type': {
                'device_type': 'LINUX',
                'architecture': '64',
                'type': 'SUSE',
                'version': '1.2.3.4'
            },
            'sensor_url': 'X',
            'sensor_config_url': 'Y',
            'error_code': None,
            'message': None
        })
    assert skit2.sensor_type == skit.sensor_type
コード例 #2
0
def test_sensor_install_bulk_by_id(cbcsdk_mock):
    """Test the bulk_install_by_id function on ComputeResource."""
    def validate_post(url, param_table, **kwargs):
        assert kwargs['action_type'] == 'INSTALL'
        assert kwargs['file'] == 'MyConfigFile'
        r = json.loads(kwargs['install_request'])
        assert r == {
            'compute_resources': [{
                'resource_manager_id': 'Alpha',
                'compute_resource_id': '1'
            }, {
                'resource_manager_id': 'Bravo',
                'compute_resource_id': '2'
            }],
            'sensor_types': [{
                'device_type': 'LINUX',
                'architecture': '64',
                'type': 'SUSE',
                'version': '1.2.3.4'
            }, {
                'device_type': 'MAC',
                'architecture': '64',
                'type': 'MAC',
                'version': '5.6.7.8'
            }]
        }
        return REQUEST_SENSOR_INSTALL_RESP

    cbcsdk_mock.mock_request("POST_MULTIPART",
                             "/lcm/v1/orgs/test/workloads/actions",
                             validate_post)
    api = cbcsdk_mock.api
    skit1 = SensorKit.from_type(api, 'LINUX', '64', 'SUSE', '1.2.3.4')
    skit2 = SensorKit.from_type(api, 'MAC', '64', 'MAC', '5.6.7.8')
    result = ComputeResource.bulk_install_by_id(
        api, [{
            'resource_manager_id': 'Alpha',
            'compute_resource_id': '1'
        }, {
            'resource_manager_id': 'Bravo',
            'compute_resource_id': '2'
        }], [skit1, skit2], 'MyConfigFile')
    assert result == {
        'type': "INFO",
        'code': "INSTALL_SENSOR_REQUEST_PROCESSED"
    }
コード例 #3
0
def test_sensor_query(cbcsdk_mock):
    """Test the sensor kit query."""
    def validate_post(url, param_table, **kwargs):
        assert kwargs['configParams'] == 'SampleConfParams'
        r = json.loads(kwargs['sensor_url_request'])
        assert r == {
            'sensor_types': [{
                'device_type': 'LINUX',
                'architecture': '64',
                'type': 'SUSE',
                'version': '1.2.3.4'
            }, {
                'device_type': 'MAC',
                'architecture': '64',
                'type': 'MAC',
                'version': '5.6.7.8'
            }],
            'expires_at':
            '2021-04-01T23:39:52Z'
        }
        return GET_SENSOR_INFO_RESP

    cbcsdk_mock.mock_request("POST_MULTIPART",
                             "/lcm/v1/orgs/test/sensor/_download",
                             validate_post)
    api = cbcsdk_mock.api
    query = api.select(SensorKit)
    query.add_sensor_kit_type(device_type='LINUX',
                              architecture='64',
                              sensor_type='SUSE',
                              version='1.2.3.4')
    skit = SensorKit.from_type(api, 'MAC', '64', 'MAC', '5.6.7.8')
    query.add_sensor_kit_type(skit).expires(
        '2021-04-01T23:39:52Z').config_params('SampleConfParams')
    assert query._count() == 2
    result = list(query)
    assert len(result) == 2
    assert result[0].sensor_type == {
        'device_type': 'LINUX',
        'architecture': '64',
        'type': 'SUSE',
        'version': '1.2.3.4'
    }
    assert result[0].sensor_url == "https://SensorURL1"
    assert result[0].sensor_config_url == "https://SensorConfigURL1"
    assert result[0].error_code == "NoErr1"
    assert result[0].message == "Message1"
    assert result[1].sensor_type == {
        'device_type': 'MAC',
        'architecture': '64',
        'type': 'MAC',
        'version': '5.6.7.8'
    }
    assert result[1].sensor_url == "https://SensorURL2"
    assert result[1].sensor_config_url == "https://SensorConfigURL2"
    assert result[1].error_code == "NoErr2"
    assert result[1].message == "Message2"
コード例 #4
0
def test_get_config_template(cbcsdk_mock):
    """Test the get_config_template function."""
    cbcsdk_mock.mock_request("RAW_GET",
                             "/lcm/v1/orgs/test/sensor/config_template",
                             GET_CONFIG_TEMPLATE_RESP)
    api = cbcsdk_mock.api
    result = SensorKit.get_config_template(api)
    assert "ALSK12KHG83B110DKK" in result
    assert "ABCD1234" in result
    assert "backendserver.org" in result
コード例 #5
0
    def _build_desired_sensorkit(self, version):
        """
        Builds a SensorKit to be used to specify the sensor to be installed on this compute resource.

        May also raise errors if the compute resource is ineligible or has an invalid type.

        Args:
            version (str): The version number of the sensor to be used.

        Returns:
            SensorKit: A SensorKit object configured with the right sensor type values.

        Raises:
            ApiError: If the compute node is not eligible or is of an invalid type.
        """
        my_type = self._get_sensor_type()
        if my_type in ('WINDOWS', 'MAC'):
            my_device_type = my_type
        else:
            my_device_type = 'LINUX'
        return SensorKit.from_type(self._cb, my_device_type, self.os_architecture, my_type, version)
コード例 #6
0
def test_sensorkit_from_type_fail(cb, device_type, arch, sensor_type):
    """Test errors raised with bogus values for SensorKit."""
    with pytest.raises(ApiError):
        SensorKit.from_type(cb, device_type, arch, sensor_type, '1.2.3.4')