コード例 #1
0
ファイル: TMCloneCacheTest.py プロジェクト: StratusLab/client
    def test_updatePDiskSrcUrlFromPublicToLocalIp(self):
        tm = TMCloneCache({TMCloneCache._ARG_SRC_POS : 'foo:bar',
                           TMCloneCache._ARG_DST_POS : 'foo:bar',
                           'bar' : 'baz'},
                           conf_filename=self.conf_filename)
        assert 'https://example.com:8445' == tm.persistentDiskPublicBaseUrl
        tm.diskSrc = 'https://%s/uuid-123' % Util.getHostnamePortFromUri(
                                                tm.persistentDiskPublicBaseUrl)
        tm._updatePDiskSrcUrlFromPublicToLocalIp()
        assert 'https://127.0.0.1:8445/uuid-123' == tm.diskSrc

        # The URI shouldn't be updated when it points to an IP different to the public one.
        tm._updatePDiskSrcUrlFromPublicToLocalIp()
        assert 'https://127.0.0.1:8445/uuid-123' == tm.diskSrc
コード例 #2
0
ファイル: TMCloneCacheTest.py プロジェクト: StratusLab/client
    def test_checkAuthorization(self):
        tm = TMCloneCache({TMCloneCache._ARG_SRC_POS : 'foo:bar',
                           TMCloneCache._ARG_DST_POS : 'foo:bar',
                           'bar' : 'baz'},
                           conf_filename=self.conf_filename)

        tm._deriveVMOwner = Mock(return_value='jayrandom')
        tm._getDiskOwner = Mock(return_value='jayrandom')
        tm._getDiskVisibility = Mock(return_value='whatever')
        try:
            tm._checkAuthorization()
        except ValueError:
            self.fail('Should not have thrown ValueError')

        tm._deriveVMOwner = Mock(return_value='jayrandom')
        tm._getDiskOwner = Mock(return_value='jayrandom')
        tm._getDiskVisibility = Mock(return_value=tm._DISK_UNAUTHORIZED_VISIBILITIES[0])
        try:
            tm._checkAuthorization()
        except ValueError:
            self.fail('Should not have thrown ValueError')

        tm._deriveVMOwner = Mock(return_value='jayrandom')
        tm._getDiskOwner = Mock(return_value='johndoe')
        tm._getDiskVisibility = Mock(return_value='whatever')
        try:
            tm._checkAuthorization()
        except ValueError:
            self.fail('Should not have thrown ValueError')

        tm._deriveVMOwner = Mock(return_value='jayrandom')
        tm._getDiskOwner = Mock(return_value='johndoe')
        tm._getDiskVisibility = Mock(return_value=tm._DISK_UNAUTHORIZED_VISIBILITIES[0])
        self.failUnlessRaises(ValueError, tm._checkAuthorization)

        tm._deriveVMOwner = Mock(return_value='jayrandom')
        tm._getDiskOwner = Mock(return_value=tm._PDISK_SUPERUSER)
        tm._getDiskVisibility = Mock(return_value=tm._DISK_UNAUTHORIZED_VISIBILITIES[0])
        try:
            tm._checkAuthorization()
        except ValueError:
            self.fail('Should not have thrown ValueError')
コード例 #3
0
ファイル: tm_clone_cache.py プロジェクト: StratusLab/one
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import sys

sys.path.append('/var/lib/stratuslab/python')

from stratuslab.tm.TMCloneCache import TMCloneCache

if __name__ == '__main__':
    try:
        tm = TMCloneCache(sys.argv)
        tm.run()
    except Exception, e:
        print >> sys.stderr, 'ERROR MESSAGE --8<------'
        print >> sys.stderr, '%s: %s' % (os.path.basename(__file__), e)
        print >> sys.stderr, 'ERROR MESSAGE ------>8--'
        if TMCloneCache.PRINT_TRACE_ON_ERROR: 
            raise
        sys.exit(1)