def test_version_parsing(self):
        versions = [
            ('2.0.0', (2, 0, 0, 0, 0)),
            ('3.1.0', (3, 1, 0, 0, 0)),
            ('2.4.54', (2, 4, 54, 0, 0)),
            ('3.1.1.12', (3, 1, 1, 12, 0)),
            ('3.55.1.build12', (3, 55, 1, 'build12', 0)),
            ('3.55.1.20190429-TEST', (3, 55, 1, 20190429, 'TEST')),
            ('4.0-SNAPSHOT', (4, 0, 0, 0, 'SNAPSHOT')),
        ]

        for str_version, expected_result in versions:
            v = Version(str_version)
            self.assertEqual(str_version, str(v))
            self.assertEqual(v.major, expected_result[0])
            self.assertEqual(v.minor, expected_result[1])
            self.assertEqual(v.patch, expected_result[2])
            self.assertEqual(v.build, expected_result[3])
            self.assertEqual(v.prerelease, expected_result[4])

        # not supported version formats
        with self.assertRaises(ValueError):
            Version('2.1.hello')

        with self.assertRaises(ValueError):
            Version('2.test.1')

        with self.assertRaises(ValueError):
            Version('test.1.0')

        with self.assertRaises(ValueError):
            Version('1.0.0.0.1')
Exemple #2
0
    def test_version_parsing(self):

        versions = [(2, 0, 0), (3, 1, 0), (2, 4, 54), (3, 1, 1, 12),
                    (3, 55, 1, 'build12'), (3, 55, 1, '20190429-TEST')]

        for version in versions:
            str_version = '.'.join([str(p) for p in version])
            v = Version(str_version)
            self.assertEqual(str_version, str(v))
            self.assertEqual(v.major, version[0])
            self.assertEqual(v.minor, version[1])
            self.assertEqual(v.patch, version[2])
            if len(version) > 3:
                self.assertEqual(v.build, version[3])

        # not supported version formats
        with self.assertRaises(ValueError):
            Version('2.1.hello')

        with self.assertRaises(ValueError):
            Version('2.test.1')

        with self.assertRaises(ValueError):
            Version('test.1.0')

        with self.assertRaises(ValueError):
            Version('1.0.0.0.1')
Exemple #3
0
    def storage_port(self):
        """
        SSL port, for legacy encrypted communication. The ssl_storage_port is unused unless enabled in
        server_encryption_options. As of cassandra 4.0, this property is deprecated
        as a single port can be used for either/both secure and insecure connections.
        """
        if 'server_encryption_options' in self._config and \
                self._config['server_encryption_options']['internode_encryption'] is not None and \
                self._config['server_encryption_options']['internode_encryption'] != "none":

            # Secure connections, ssl_storage_port is specified.
            if 'ssl_storage_port' in self._config and self._config[
                    'ssl_storage_port'] is not None:
                logging.warning(
                    "ssl_storage_port is deprecated as of Apache Cassandra 4.x"
                )
                return self._config['ssl_storage_port']
            else:
                # ssl_storage_port not specified, and found a version of c* 4+
                if self._release_version is not None and Version(self._release_version) >= Version('4-a') and \
                        'storage_port' in self._config and self._config['storage_port'] is not None:
                    return self._config['storage_port']
                return "7001"

        # Insecure connection handling of storage_port for any version of c*
        if 'storage_port' in self._config and self._config[
                'storage_port'] is not None:
            return self._config['storage_port']
        return "7000"
    def set_release_version(version):
        if not version:
            raise RuntimeError('No version supplied.')

        if not HostMan.__instance:
            HostMan()

        HostMan.__instance.__release_version = Version(version)
Exemple #5
0
    def test_capture_release_version_from_default(self, mock_storage,
                                                  mock_abstract_storage):
        # WHEN api_version is not available from either CLI or the driver.
        mock_abstract_storage.driver = BaseDriver(key=Mock())
        mock_storage.attach_mock(mock_abstract_storage, 'storage_driver')
        restore_node.capture_release_version(mock_storage, None)

        # THEN expect default release version will be captured.
        self.assertEqual(HostMan.get_release_version(),
                         Version(HostMan.DEFAULT_RELEASE_VERSION))
Exemple #6
0
    def test_capture_release_version_from_driver(self, mock_storage,
                                                 mock_abstract_storage):
        # WHEN api_version from driver is specified and no specified CLI version.
        mock_abstract_storage.driver = BaseDriver(key=Mock(),
                                                  api_version='5.0.0')
        mock_storage.attach_mock(mock_abstract_storage, 'storage_driver')
        restore_node.capture_release_version(mock_storage, None)

        # THEN expect the api_version from driver is captured.
        self.assertEqual(HostMan.get_release_version(), Version('5.0.0'))
Exemple #7
0
    def test_capture_release_version_from_CLI(self, mock_storage,
                                              mock_abstract_storage):
        # WHEN api_version is specified from CLI, and api_version is available from driver.
        mock_abstract_storage.driver = BaseDriver(key=Mock(),
                                                  api_version='5.0.0')
        mock_storage.attach_mock(mock_abstract_storage, 'storage_driver')
        restore_node.capture_release_version(mock_storage, '4.0.0')

        # THEN expect the api_version from driver is captured.
        self.assertEqual(HostMan.get_release_version(), Version('4.0.0'))
    def test_get_release_version(self):
        rv_1 = "1.2.3"
        rv_2 = "5.6.7"
        rv_3 = "10.11.12"

        HostMan.set_release_version(rv_1)
        HostMan.set_release_version(rv_2)
        HostMan.set_release_version(rv_3)

        self.assertEqual(HostMan.get_release_version(), Version(rv_3))
Exemple #9
0
def version_supports_insights(dse_version):
    if dse_version:
        try:
            dse_version = Version(dse_version)
            return (DSE_51_MIN_SUPPORTED <= dse_version < DSE_60
                    or
                    DSE_60_MIN_SUPPORTED <= dse_version)
        except Exception:
            warn("Unable to check version {v} for Insights compatibility, returning False. "
                 "Exception: \n{e}".format(e=traceback.format_exc(), v=dse_version))

    return False
Exemple #10
0
# 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 logging
import traceback
from warnings import warn

from cassandra.util import Version


DSE_60 = Version('6.0.0')
DSE_51_MIN_SUPPORTED = Version('5.1.13')
DSE_60_MIN_SUPPORTED = Version('6.0.5')


log = logging.getLogger(__name__)


def namespace(cls):
    """
    Best-effort method for getting the namespace in which a class is defined.
    """
    try:
        # __module__ can be None
        module = cls.__module__ or ''
    except Exception:
    def test_version_compare(self):
        # just tests a bunch of versions

        # major wins
        self.assertTrue(Version('3.3.0') > Version('2.5.0'))
        self.assertTrue(Version('3.3.0') > Version('2.5.0.66'))
        self.assertTrue(Version('3.3.0') > Version('2.5.21'))

        # minor wins
        self.assertTrue(Version('2.3.0') > Version('2.2.0'))
        self.assertTrue(Version('2.3.0') > Version('2.2.7'))
        self.assertTrue(Version('2.3.0') > Version('2.2.7.9'))

        # patch wins
        self.assertTrue(Version('2.3.1') > Version('2.3.0'))
        self.assertTrue(Version('2.3.1') > Version('2.3.0.4post0'))
        self.assertTrue(Version('2.3.1') > Version('2.3.0.44'))

        # various
        self.assertTrue(Version('2.3.0.1') > Version('2.3.0.0'))
        self.assertTrue(Version('2.3.0.680') > Version('2.3.0.670'))
        self.assertTrue(Version('2.3.0.681') > Version('2.3.0.680'))
        self.assertTrue(Version('2.3.0.1build0') >
                        Version('2.3.0.1'))  # 4th part fallback to str cmp
        self.assertTrue(Version('2.3.0.build0') >
                        Version('2.3.0.1'))  # 4th part fallback to str cmp
        self.assertTrue(Version('2.3.0') < Version('2.3.0.build'))

        self.assertTrue(Version('4.0.0') >= Version('4.0.0'))
        self.assertTrue(Version('4.0.0.421') >= Version('4.0.0'))
        self.assertTrue(Version('4.0.1') >= Version('4.0.0'))
        self.assertTrue(Version('2.3.0') == Version('2.3.0'))
        self.assertTrue(Version('2.3.32') == Version('2.3.32'))
        self.assertTrue(Version('2.3.32') == Version('2.3.32.0'))
        self.assertTrue(Version('2.3.0.build') == Version('2.3.0.build'))

        self.assertTrue(Version('4') == Version('4.0.0'))
        self.assertTrue(Version('4.0') == Version('4.0.0.0'))
        self.assertTrue(Version('4.0') > Version('3.9.3'))

        self.assertTrue(Version('4.0') > Version('4.0-SNAPSHOT'))
        self.assertTrue(Version('4.0-SNAPSHOT') == Version('4.0-SNAPSHOT'))
        self.assertTrue(Version('4.0.0-SNAPSHOT') == Version('4.0-SNAPSHOT'))
        self.assertTrue(Version('4.0.0-SNAPSHOT') == Version('4.0.0-SNAPSHOT'))
        self.assertTrue(
            Version('4.0.0.build5-SNAPSHOT') == Version(
                '4.0.0.build5-SNAPSHOT'))
        self.assertTrue(Version('4.1-SNAPSHOT') > Version('4.0-SNAPSHOT'))
        self.assertTrue(Version('4.0.1-SNAPSHOT') > Version('4.0.0-SNAPSHOT'))
        self.assertTrue(
            Version('4.0.0.build6-SNAPSHOT') > Version('4.0.0.build5-SNAPSHOT')
        )
        self.assertTrue(Version('4.0-SNAPSHOT2') > Version('4.0-SNAPSHOT1'))
        self.assertTrue(Version('4.0-SNAPSHOT2') > Version('4.0.0-SNAPSHOT1'))