Warn when cqlsh does not match the server version it was built with

Patch by brandonwilliams; reviewed by bereng for CASSANDRA-18745
This commit is contained in:
Brandon Williams 2023-08-17 13:23:47 -05:00
parent fd9f07dab8
commit 6bb585bf5d
4 changed files with 38 additions and 1 deletions

24
.build/build-cqlsh.xml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<project basedir="." name="apache-cassandra-cqlsh-tasks"
xmlns:if="ant:if">
<target name="set-cqlsh-version">
<echo file="pylib/cqlshlib/serverversion.py" append="false">version = "${base.version}"${line.separator}</echo>
</target>
</project>

View File

@ -1,4 +1,5 @@
3.0.30 3.0.30
* CQLSH emits a warning when the server version doesn't match (CASSANDRA-18745)
* Fix missing speculative retries in tablestats (CASSANDRA-18767) * Fix missing speculative retries in tablestats (CASSANDRA-18767)
* Fix Requires for Java for RPM package (CASSANDRA-18751) * Fix Requires for Java for RPM package (CASSANDRA-18751)
* Fix CQLSH online help topic link (CASSANDRA-17534) * Fix CQLSH online help topic link (CASSANDRA-17534)

View File

@ -171,6 +171,7 @@ from cqlshlib.formatting import (DEFAULT_DATE_FORMAT, DEFAULT_NANOTIME_FORMAT,
formatter_for) formatter_for)
from cqlshlib.tracing import print_trace, print_trace_session from cqlshlib.tracing import print_trace, print_trace_session
from cqlshlib.util import get_file_encoding_bomsize, trim_if_present from cqlshlib.util import get_file_encoding_bomsize, trim_if_present
from cqlshlib.serverversion import version as build_version
DEFAULT_HOST = '127.0.0.1' DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 9042 DEFAULT_PORT = 9042
@ -797,6 +798,8 @@ class Shell(cmd.Cmd):
if stdin is None: if stdin is None:
stdin = sys.stdin stdin = sys.stdin
self.check_build_versions()
if tty: if tty:
self.reset_prompt() self.reset_prompt()
self.report_connection() self.report_connection()
@ -816,6 +819,14 @@ class Shell(cmd.Cmd):
def batch_mode(self): def batch_mode(self):
return not self.tty return not self.tty
def check_build_versions(self):
baseversion = self.connection_versions['build']
extra = baseversion.rfind('-')
if extra:
baseversion = baseversion[0:extra]
if baseversion != build_version:
print("WARNING: cqlsh was built against {}, but this server is {}. All features may not work!".format(baseversion, build_version))
@property @property
def is_using_utf8(self): def is_using_utf8(self):
# utf8 encodings from https://docs.python.org/{2,3}/library/codecs.html # utf8 encodings from https://docs.python.org/{2,3}/library/codecs.html

View File

@ -684,7 +684,7 @@
</target> </target>
<!-- create properties file with C version --> <!-- create properties file with C version -->
<target name="createVersionPropFile"> <target name="createVersionPropFile" depends="set-cqlsh-version">
<taskdef name="propertyfile" classname="org.apache.tools.ant.taskdefs.optional.PropertyFile"/> <taskdef name="propertyfile" classname="org.apache.tools.ant.taskdefs.optional.PropertyFile"/>
<mkdir dir="${version.properties.dir}"/> <mkdir dir="${version.properties.dir}"/>
<propertyfile file="${version.properties.dir}/version.properties"> <propertyfile file="${version.properties.dir}/version.properties">
@ -1970,4 +1970,5 @@
<import file="${basedir}/.build/build-resolver.xml"/> <import file="${basedir}/.build/build-resolver.xml"/>
<import file="${basedir}/.build/build-rat.xml"/> <import file="${basedir}/.build/build-rat.xml"/>
<import file="${basedir}/.build/build-owasp.xml"/> <import file="${basedir}/.build/build-owasp.xml"/>
<import file="${basedir}/.build/build-cqlsh.xml"/>
</project> </project>