Example #1
0
    def test_stale_openstack_volumes(self):
        ctx = Mock()
        ctx.teuthology_config = config
        ctx.dry_run = False
        now = datetime.datetime.strftime(datetime.datetime.now(),
                                         "%Y-%m-%dT%H:%M:%S.000000")
        id = '4bee3af9-febb-40c1-a17e-ff63edb415c5'
        name = 'target1-0'
        volume_list = json.loads(
            '[{'
            ' "ID": "' + id + '"'
            '}]'
        )
        #
        # A volume created a second ago is left untouched
        #
        volume_show = (
            '['
            ' {"Field": "id", "Value": "' + id + '"},'
            ' {"Field": "created_at", "Value": "' + now + '"},'
            ' {"Field": "display_name", "Value": "' + name + '"}'
            ']'
        )
        def sh(cmd):
            if 'volume show' in cmd:
                return volume_show

        with patch.multiple(
                nuke,
                sh=sh,
                openstack_delete_volume=DEFAULT,
                ) as m:
            nuke.stale_openstack_volumes(ctx, volume_list)
            m['openstack_delete_volume'].assert_not_called()

        #
        # A volume created long ago is destroyed
        #
        ancient = "2000-11-02T15:43:12.000000"
        volume_show = (
            '['
            ' {"Field": "id", "Value": "' + id + '"},'
            ' {"Field": "created_at", "Value": "' + ancient + '"},'
            ' {"Field": "display_name", "Value": "' + name + '"}'
            ']'
        )
        def sh(cmd):
            if 'volume show' in cmd:
                return volume_show

        with patch.multiple(
                nuke,
                sh=sh,
                openstack_delete_volume=DEFAULT,
                ) as m:
            nuke.stale_openstack_volumes(ctx, volume_list)
            m['openstack_delete_volume'].assert_called_with(id)
Example #2
0
    def test_stale_openstack_volumes(self):
        ctx = Mock()
        ctx.teuthology_config = config
        ctx.dry_run = False
        now = datetime.datetime.strftime(datetime.datetime.now(),
                                         "%Y-%m-%dT%H:%M:%S.000000")
        id = '4bee3af9-febb-40c1-a17e-ff63edb415c5'
        name = 'target1-0'
        volume_list = json.loads(
            '[{'
            ' "ID": "' + id + '"'
            '}]'
        )
        #
        # A volume created a second ago is left untouched
        #
        volume_show = (
            '{"id": "' + id + '", '
            '"created_at": "' + now + '", '
            '"display_name": "' + name + '"}'
        )

        with patch('teuthology.nuke.openstack_delete_volume') as m_os_del_vol:
            with patch.object(nuke.OpenStack, 'run') as m_os_run:
                m_os_run.return_value = volume_show
                nuke.stale_openstack_volumes(ctx, volume_list)
                m_os_del_vol.assert_not_called()


        #
        # A volume created long ago is destroyed
        #
        ancient = "2000-11-02T15:43:12.000000"
        volume_show = (
            '{"id": "' + id + '", '
            '"created_at": "' + ancient + '", '
            '"display_name": "' + name + '"}'
        )

        with patch('teuthology.nuke.openstack_delete_volume') as m_os_del_vol:
            with patch.object(nuke.OpenStack, 'run') as m_os_run:
                m_os_run.return_value = volume_show
                nuke.stale_openstack_volumes(ctx, volume_list)
                m_os_del_vol.assert_called_with(id)

        #
        # A volume that no longer exists is ignored
        #
        with patch('teuthology.nuke.openstack_delete_volume') as m_os_del_vol:
            with patch.object(nuke.OpenStack, 'run') as m_os_run:
                m_os_run.side_effect = subprocess.CalledProcessError('ERROR', 'FAIL')
                nuke.stale_openstack_volumes(ctx, volume_list)
                m_os_del_vol.assert_not_called()
Example #3
0
    def test_stale_openstack_volumes(self):
        ctx = Mock()
        ctx.teuthology_config = config
        ctx.dry_run = False
        now = datetime.datetime.strftime(datetime.datetime.now(),
                                         "%Y-%m-%dT%H:%M:%S.000000")
        id = '4bee3af9-febb-40c1-a17e-ff63edb415c5'
        name = 'target1-0'
        volume_list = json.loads('[{' ' "ID": "' + id + '"' '}]')
        #
        # A volume created a second ago is left untouched
        #
        volume_show = ('['
                       ' {"Field": "id", "Value": "' + id + '"},'
                       ' {"Field": "created_at", "Value": "' + now + '"},'
                       ' {"Field": "display_name", "Value": "' + name + '"}'
                       ']')

        def sh(cmd):
            if 'volume show' in cmd:
                return volume_show

        with patch.multiple(
                nuke,
                sh=sh,
                openstack_delete_volume=DEFAULT,
        ) as m:
            nuke.stale_openstack_volumes(ctx, volume_list)
            m['openstack_delete_volume'].assert_not_called()

        #
        # A volume created long ago is destroyed
        #
        ancient = "2000-11-02T15:43:12.000000"
        volume_show = ('['
                       ' {"Field": "id", "Value": "' + id + '"},'
                       ' {"Field": "created_at", "Value": "' + ancient + '"},'
                       ' {"Field": "display_name", "Value": "' + name + '"}'
                       ']')

        def sh(cmd):
            if 'volume show' in cmd:
                return volume_show

        with patch.multiple(
                nuke,
                sh=sh,
                openstack_delete_volume=DEFAULT,
        ) as m:
            nuke.stale_openstack_volumes(ctx, volume_list)
            m['openstack_delete_volume'].assert_called_with(id)

        #
        # A volume that no longer exists is ignored
        #
        def sh(cmd):
            raise subprocess.CalledProcessError('ERROR', 'FAIL')

        with patch.multiple(
                nuke,
                sh=sh,
                openstack_delete_volume=DEFAULT,
        ) as m:
            nuke.stale_openstack_volumes(ctx, volume_list)
            m['openstack_delete_volume'].assert_not_called()