Exemplo n.º 1
0
 def test_lock_twise(self):
     """Tests lock behavior for re-entrant attempt
     """
     lock_thread()
     with self.assertRaises(AssertionError):
         lock_thread()
     release_thread()
Exemplo n.º 2
0
    def refresh(self, get_public_ip=False):
        """
        Fetch all instance metadata from all sources.

        Parameters
        ----------
        get_public_ip : bool
            The flag to collect the public ip address of the instance.

        Returns
        -------
            boolean
                True for success, False for failure.
        """
        #_logger.debug('refreshing metada')
        metadata = {}
        result = True

        # read the instance metadata
        lock_thread()
        try:
            _request = urllib.request.Request(
                self._oci_metadata_api_url + 'instance/',
                headers={'Authorization': 'Bearer Oracle'})
            api_conn = urllib.request.urlopen(_request, timeout=2)
            instance_metadata = json.loads(api_conn.read().decode('utf-8'))
            metadata['instance'] = instance_metadata
        except IOError as e:
            self._errors.append("Error connecting to metadata server: %s\n" %
                                e[0])
            result = False
        finally:
            release_thread()

        # get the VNIC info
        lock_thread()
        try:
            _request = urllib.request.Request(
                self._oci_metadata_api_url + 'vnics/',
                headers={'Authorization': 'Bearer Oracle'})
            api_conn = urllib.request.urlopen(_request, timeout=2)
            vnic_metadata = json.loads(api_conn.read().decode('utf-8'))
            metadata['vnics'] = vnic_metadata
        except IOError as e:
            self._errors.append("Error connecting to metadata server: %s\n" %
                                e[0])
            result = False
        finally:
            release_thread()

        if metadata:
            self._metadata = OCIMetadata(metadata)

        #_logger.debug('metadata after refresh [%s]' % str(self._metadata))
        return result
Exemplo n.º 3
0
    def refresh(self, get_public_ip=False):
        """
        Fetch all instance metadata from all sources.

        Parameters
        ----------
        get_public_ip : bool
            The flag to collect the public ip address of the instance.

        Returns
        -------
            boolean
                True for success, False for failure.
        """
        metadata = {}
        result = True

        # read the instance metadata
        lock_thread()
        try:
            api_conn = urllib2.urlopen(self._oci_metadata_api_url +
                                       'instance/',
                                       timeout=2)
            instance_metadata = json.loads(api_conn.read().decode())
            metadata['instance'] = instance_metadata
        except IOError as e:
            self._errors.append("Error connecting to metadata server: %s\n" %
                                e[0])
            result = False
        finally:
            release_thread()

        # get the VNIC info
        lock_thread()
        try:
            api_conn = urllib2.urlopen(self._oci_metadata_api_url + 'vnics/',
                                       timeout=2)
            vnic_metadata = json.loads(api_conn.read().decode())
            metadata['vnics'] = vnic_metadata
        except IOError as e:
            self._errors.append("Error connecting to metadata server: %s\n" %
                                e[0])
            result = False
        finally:
            release_thread()

        if metadata:
            self._metadata = OCIMetadata(metadata)

        return result
Exemplo n.º 4
0
 def test_unlock_unlocked(self):
     """Tests unlock behavior for not locked object
     """
     with self.assertRaises(AssertionError):
         release_thread()