def test__find_working_version_uses_latest(self):
     """'latest' should be used if no supported versions."""
     unsup1, unsup2 = ("2016-11-09", '2017-06-06')
     self.register_versions([unsup1, unsup2, openstack.OS_LATEST])
     self.assertEqual(
         openstack.OS_LATEST,
         openstack.MetadataReader(self.burl)._find_working_version())
Exemple #2
0
 def test__find_working_version(self):
     """Test a working version ignores unsupported."""
     unsup = "2016-11-09"
     self.register_versions(
         [openstack.OS_FOLSOM, openstack.OS_LIBERTY, unsup,
          openstack.OS_LATEST])
     self.assertEqual(
         openstack.OS_LIBERTY,
         openstack.MetadataReader(self.burl)._find_working_version())
Exemple #3
0
    def test_read_v2_os_ocata(self):
        """Validate return value of read_v2 for os_ocata data."""
        md = copy.deepcopy(self.md_base)
        md['devices'] = []
        network_data = {'links': [], 'networks': [], 'services': []}
        vendor_data = {}
        vendor_data2 = {"static": {}}

        data = {
            'meta_data.json': json.dumps(md),
            'network_data.json': json.dumps(network_data),
            'vendor_data.json': json.dumps(vendor_data),
            'vendor_data2.json': json.dumps(vendor_data2),
        }

        self.register_versions([openstack.OS_OCATA, openstack.OS_LATEST])
        self.register_version(openstack.OS_OCATA, data)

        mock_read_ec2 = test_helpers.mock.MagicMock(
            return_value={'instance-id': 'unused-ec2'})
        expected_md = copy.deepcopy(md)
        expected_md.update({
            'instance-id': md['uuid'],
            'local-hostname': md['hostname']
        })
        expected = {
            'userdata': '',  # Annoying, no user-data results in empty string.
            'version': 2,
            'metadata': expected_md,
            'vendordata': vendor_data,
            'vendordata2': vendor_data2,
            'networkdata': network_data,
            'ec2-metadata': mock_read_ec2.return_value,
            'files': {},
        }
        reader = openstack.MetadataReader(self.burl)
        reader._read_ec2_metadata = mock_read_ec2
        self.assertEqual(expected, reader.read_v2())
        self.assertEqual(1, mock_read_ec2.call_count)
    def test_read_v2_os_ocata(self):
        """Validate return value of read_v2 for os_ocata data."""
        md = copy.deepcopy(self.md_base)
        md["devices"] = []
        network_data = {"links": [], "networks": [], "services": []}
        vendor_data = {}
        vendor_data2 = {"static": {}}

        data = {
            "meta_data.json": json.dumps(md),
            "network_data.json": json.dumps(network_data),
            "vendor_data.json": json.dumps(vendor_data),
            "vendor_data2.json": json.dumps(vendor_data2),
        }

        self.register_versions([openstack.OS_OCATA, openstack.OS_LATEST])
        self.register_version(openstack.OS_OCATA, data)

        mock_read_ec2 = test_helpers.mock.MagicMock(
            return_value={"instance-id": "unused-ec2"})
        expected_md = copy.deepcopy(md)
        expected_md.update({
            "instance-id": md["uuid"],
            "local-hostname": md["hostname"]
        })
        expected = {
            "userdata": "",  # Annoying, no user-data results in empty string.
            "version": 2,
            "metadata": expected_md,
            "vendordata": vendor_data,
            "vendordata2": vendor_data2,
            "networkdata": network_data,
            "ec2-metadata": mock_read_ec2.return_value,
            "files": {},
        }
        reader = openstack.MetadataReader(self.burl)
        reader._read_ec2_metadata = mock_read_ec2
        self.assertEqual(expected, reader.read_v2())
        self.assertEqual(1, mock_read_ec2.call_count)
def read_metadata_service(base_url, ssl_details=None, timeout=5, retries=5):
    reader = openstack.MetadataReader(base_url,
                                      ssl_details=ssl_details,
                                      timeout=timeout,
                                      retries=retries)
    return reader.read_v2()
Exemple #6
0
def read_metadata_service(base_url, ssl_details=None):
    reader = openstack.MetadataReader(base_url, ssl_details=ssl_details)
    return reader.read_v2()