Exemplo n.º 1
0
    def test_media_update(self):
        """test updating media."""
        client = Client()
        client.connect()
        self.pho_execute(['tape', 'add', '-t', 'LTO6', '--fs', 'LTFS',
                          'update0', '--tags', 'tag-foo'])
        self.pho_execute(['tape', 'add', '-t', 'LTO6', '--fs', 'LTFS',
                          'update1', '--tags', 'tag-foo,tag-bar'])

        # Check inserted media
        update0, = client.media.get(id="update0")
        update1, = client.media.get(id="update1")
        self.assertItemsEqual(update0.tags, ['tag-foo'])
        self.assertItemsEqual(update1.tags, ['tag-foo', 'tag-bar'])

        # Update media
        self.pho_execute(['tape', 'update', '-T', 'new-tag1,new-tag2',
                          'update[0-1]'])

        # Check updated media
        for med_id in "update0", "update1":
            media, = client.media.get(id=med_id)
            self.assertItemsEqual(media.tags, ['new-tag1', 'new-tag2'])

        # No '-T' argument does nothing
        self.pho_execute(['tape', 'update', 'update0'])
        update0, = client.media.get(id=med_id)
        self.assertItemsEqual(update0.tags, ['new-tag1', 'new-tag2'])

        # Test a failed update
        def failed_update(*args, **kwargs):
            """Emulates a failed update by raising EnvironmentError"""
            raise EnvironmentError(errno.ENOENT, "Expected failed")

        old_update = MediaManager.update
        MediaManager.update = failed_update
        try:
            self.pho_execute(['tape', 'update', '-T', '', 'update0'],
                             code=os.EX_DATAERR)
        finally:
            MediaManager.update = old_update

        # Ensure that the tape is unlocked after failure
        client = Client()
        client.connect()
        # Exactly one media should be returned
        media, = client.media.get(id='update0')
        self.assertFalse(media.is_locked())

        # Check that locked tapes cannot be updated
        client.media.lock([media])
        try:
            self.pho_execute(['tape', 'update', '-T', '', 'update0'],
                             code=os.EX_DATAERR)
        finally:
            client.media.unlock([media])
Exemplo n.º 2
0
 def test_add_tags(self):
     """Test that tags are properly added"""
     self.pho_execute(['tape', 'add', '-t', 'LTO6', '--fs', 'LTFS',
                       'TAGGED0', '--tags', 'tag-foo'])
     self.pho_execute(['tape', 'add', '-t', 'LTO6', '--fs', 'LTFS',
                       'TAGGED1', '--tags', 'tag-foo,tag-bar'])
     # Check that tags have successfully been added
     client = Client()
     client.connect()
     tagged0, = client.media.get(id='TAGGED0')
     tagged1, = client.media.get(id='TAGGED1')
     self.assertItemsEqual(tagged0.tags, ['tag-foo'])
     self.assertItemsEqual(tagged1.tags, ['tag-foo', 'tag-bar'])
Exemplo n.º 3
0
class DSSInteractHandler(BaseOptHandler):
    """Option handler for actions that interact with the DSS."""
    def __init__(self, params, **kwargs):
        """Initialize a new instance."""
        super(DSSInteractHandler, self).__init__(params, **kwargs)
        self.client = None

    def __enter__(self):
        """Initialize a DSS Client."""
        self.client = DSSClient()
        self.client.connect()
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        """Release resources associated to a DSS handle."""
        self.client.disconnect()
Exemplo n.º 4
0
    def test_dir_update(self):
        """Test updating a directory."""
        tmp_f = tempfile.NamedTemporaryFile()
        tmp_path = tmp_f.name
        client = Client()
        client.connect()
        self.pho_execute(['dir', 'add', tmp_path, '--tags', 'tag-baz'])

        # Check inserted media
        media, = client.media.get(id=tmp_path)
        self.assertItemsEqual(media.tags, ['tag-baz'])

        # Update media
        self.pho_execute(['dir', 'update', '-T', '', tmp_path])

        # Check updated media
        media, = client.media.get(id=tmp_path)
        self.assertItemsEqual(media.tags, [])
Exemplo n.º 5
0
 def test_client_connect(self): # pylint: disable=no-self-use
     """Connect to backend with valid parameters."""
     cli = Client()
     cli.connect()
     cli.disconnect()
Exemplo n.º 6
0
 def test_client_connect(self):
     """Connect to backend with valid parameters."""
     cli = Client()
     cli.connect()
     cli.disconnect()