Skip to content

Commit

Permalink
refactor(naming): refactored naming around ip addresses
Browse files Browse the repository at this point in the history
Because it's not always `ip address` but sometimes dns name, refactored
some methods names to reflect that new truth.
  • Loading branch information
soyacz authored and fruch committed Sep 18, 2023
1 parent 7b27bad commit 92f2e24
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 59 deletions.
2 changes: 2 additions & 0 deletions defaults/test_default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,6 @@ run_fullscan: []
stress_step_duration: '15m'
simulated_racks: 0

use_dns_names: false

use_placement_group: false
4 changes: 2 additions & 2 deletions functional_tests/scylla_operator/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ def test_operator_managed_tls(db_cluster: ScyllaPodCluster, tmp_path: path.Path)
db_cluster.nodes[0].refresh_ip_address()

execution_profile = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy([
db_cluster.nodes[0].cql_ip_address]))
cluster = Cluster(contact_points=[db_cluster.nodes[0].cql_ip_address], port=db_cluster.nodes[0].CQL_SSL_PORT,
db_cluster.nodes[0].cql_address]))
cluster = Cluster(contact_points=[db_cluster.nodes[0].cql_address], port=db_cluster.nodes[0].CQL_SSL_PORT,
execution_profiles={EXEC_PROFILE_DEFAULT: execution_profile})
ssl_context = ssl.SSLContext(protocol=ssl.PROTOCOL_SSLv23)
ssl_context.verify_mode = ssl.VerifyMode.CERT_REQUIRED # pylint: disable=no-member
Expand Down
2 changes: 1 addition & 1 deletion longevity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _run_stress_in_batches(self, total_stress, batch_size, stress_cmd):

@property
def all_node_ips_for_stress_command(self):
return f' -node {",".join([n.cql_ip_address for n in self.db_cluster.nodes])}'
return f' -node {",".join([n.cql_address for n in self.db_cluster.nodes])}'

@staticmethod
def _get_columns_num_of_single_stress(single_stress_cmd):
Expand Down
2 changes: 1 addition & 1 deletion sdcm/cassandra_harry_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, *args, **kwargs):

def _run_stress(self, loader, loader_idx, cpu_idx):
# Select first seed node to send the scylla-harry cmds
ip = self.node_list[0].cql_ip_address
ip = self.node_list[0].cql_address

if not os.path.exists(loader.logdir):
os.makedirs(loader.logdir, exist_ok=True)
Expand Down
67 changes: 42 additions & 25 deletions sdcm/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def __init__(self, name, parent_cluster, ssh_login_info=None, base_logdir=None,

self.remoter: Optional[RemoteCmdRunnerBase] = None

self._use_dns_names: bool = parent_cluster.params.get('use_dns_names') or False
self._use_dns_names: bool = parent_cluster.params.get('use_dns_names') if parent_cluster else False
self._spot_monitoring_thread = None
self._journal_thread = None
self._docker_log_process = None
Expand Down Expand Up @@ -434,8 +434,9 @@ def proposed_scylla_yaml(self) -> ScyllaYaml:
def refresh_ip_address(self):
# Invalidate ip address cache
self._private_ip_address_cached = self._public_ip_address_cached = self._ipv6_ip_address_cached = None
self.__dict__.pop('cql_ip_address', None)

self.__dict__.pop('cql_address', None)
self.__dict__.pop('public_dns_name', None)
self.__dict__.pop('private_dns_name', None)
if self.ssh_login_info["hostname"] == self.external_address:
return

Expand Down Expand Up @@ -861,7 +862,7 @@ def _refresh_instance_state(self):
raise NotImplementedError()

@cached_property
def cql_ip_address(self):
def cql_address(self):
if self.test_config.IP_SSH_CONNECTIONS == 'public':
return self.external_address
with self.remote_scylla_yaml() as scylla_yaml:
Expand Down Expand Up @@ -3386,7 +3387,7 @@ def get_node_public_ips(self):
return [node.public_ip_address for node in self.nodes]

def get_node_cql_ips(self):
return [node.cql_ip_address for node in self.nodes]
return [node.cql_address for node in self.nodes]

def get_node_database_errors(self):
errors = {}
Expand Down Expand Up @@ -3533,7 +3534,7 @@ def host_filter(host):
wlrr = HostFilterPolicy(child_policy=RoundRobinPolicy(), predicate=host_filter)
node_ips = []
else:
node_ips = [node.cql_ip_address]
node_ips = [node.cql_address]
wlrr = WhiteListRoundRobinPolicy(node_ips)
return self._create_session(node=node, keyspace=keyspace, user=user, password=password,
compression=compression, protocol_version=protocol_version,
Expand Down Expand Up @@ -3932,42 +3933,42 @@ def set_seeds(self, wait_for_timeout=300, first_only=False):
seeds_selector = self.params.get('seeds_selector')
seeds_num = self.params.get('seeds_num')

seed_nodes_ips = None
seed_nodes_addresses = None
if first_only:
node = self.nodes[0]
node.wait_ssh_up()
seed_nodes_ips = [node.ip_address]
seed_nodes_addresses = [node.scylla_listen_address]
elif seeds_selector == "all":
seed_nodes_ips = [node.ip_address for node in self.nodes]
seed_nodes_addresses = [node.scylla_listen_address for node in self.nodes]
elif self.test_config.REUSE_CLUSTER or self.params.get('db_type') == 'cloud_scylla':
node = self.nodes[0]
node.wait_ssh_up()
seed_nodes_ips = wait.wait_for(self.read_seed_info_from_scylla_yaml,
step=10, text='Waiting for seed read from scylla yaml',
timeout=wait_for_timeout, throw_exc=True)
seed_nodes_addresses = wait.wait_for(self.read_seed_info_from_scylla_yaml,
step=10, text='Waiting for seed read from scylla yaml',
timeout=wait_for_timeout, throw_exc=True)
else:
if seeds_selector == 'random':
selected_nodes = random.sample(self.nodes, seeds_num)
# seeds_selector == 'first'
else:
selected_nodes = self.nodes[:seeds_num]

seed_nodes_ips = [node.ip_address for node in selected_nodes]
seed_nodes_addresses = [node.scylla_listen_address for node in selected_nodes]

for node in self.nodes:
if node.ip_address in seed_nodes_ips:
if node.scylla_listen_address in seed_nodes_addresses:
node.set_seed_flag(True)

assert seed_nodes_ips, "We should have at least one selected seed by now"
assert seed_nodes_addresses, "We should have at least one selected seed by now"

@property
def seed_nodes_ips(self):
def seed_nodes_addresses(self):
if self.params.get('use_dns_names'):
seed_nodes_ips = [node.private_dns_name for node in self.nodes if node.is_seed]
seed_nodes_addresses = [node.private_dns_name for node in self.nodes if node.is_seed]
else:
seed_nodes_ips = [node.ip_address for node in self.nodes if node.is_seed]
assert seed_nodes_ips, "We should have at least one selected seed by now"
return seed_nodes_ips
seed_nodes_addresses = [node.ip_address for node in self.nodes if node.is_seed]
assert seed_nodes_addresses, "We should have at least one selected seed by now"
return seed_nodes_addresses

@property
def seed_nodes(self):
Expand All @@ -3983,10 +3984,10 @@ def validate_seeds_on_all_nodes(self):
for node in self.nodes:
yaml_seeds_ips = node.extract_seeds_from_scylla_yaml()
for ip in yaml_seeds_ips:
assert ip in self.seed_nodes_ips, \
assert ip in self.seed_nodes_addresses, \
'Wrong seed IP {act_ip} in the scylla.yaml on the {node_name} node. ' \
'Expected {exp_ips}'.format(node_name=node.name,
exp_ips=self.seed_nodes_ips,
exp_ips=self.seed_nodes_addresses,
act_ip=ip)

@contextlib.contextmanager
Expand Down Expand Up @@ -4676,10 +4677,10 @@ def read_seed_info_from_scylla_yaml(self, node=None):
if not node:
node = self.nodes[0]

seed_nodes_ips = node.extract_seeds_from_scylla_yaml()
seed_nodes_addresses = node.extract_seeds_from_scylla_yaml()
# When cluster just started, seed IP in the scylla.yaml may be like '127.0.0.1'
# In this case we want to ignore it and wait, when reflector will select real node and update scylla.yaml
return [n.ip_address for n in self.nodes if n.ip_address in seed_nodes_ips]
return [n.ip_address for n in self.nodes if n.ip_address in seed_nodes_addresses]

def get_node(self):
if not self._node_cycle:
Expand Down Expand Up @@ -4812,7 +4813,7 @@ def create_cluster_manager(self, cluster_name: str, manager_tool=None, host_ip=N
if manager_tool is None:
manager_tool = mgmt.get_scylla_manager_tool(manager_node=self.scylla_manager_node, scylla_cluster=self)
if host_ip is None:
host_ip = self.nodes[0].ip_address
host_ip = self.nodes[0].scylla_listen_address
credentials = self.get_db_auth() # pylint: disable=no-member
return manager_tool.add_cluster(name=cluster_name, host=host_ip, auth_token=self.scylla_manager_auth_token,
credentials=credentials)
Expand Down Expand Up @@ -5772,7 +5773,23 @@ def _get_ipv6_ip_address(self):
def check_spot_termination(self):
pass

@property
def private_dns_name(self):
raise NotImplementedError()

@property
def public_dns_name(self) -> str:
raise NotImplementedError()


class LocalK8SHostNode(LocalNode):
def configure_remote_logging(self):
self.log.debug("No need to configure remote logging on k8s")

@property
def private_dns_name(self):
raise NotImplementedError()

@property
def public_dns_name(self) -> str:
raise NotImplementedError()
4 changes: 2 additions & 2 deletions sdcm/cluster_k8s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ def _container_status(self):
return None

@property
def cql_ip_address(self):
def cql_address(self):
return self.ip_address

@property
Expand Down Expand Up @@ -2576,7 +2576,7 @@ def install_scylla_manager(self, node):
pass

@property
def seed_nodes_ips(self):
def seed_nodes_addresses(self):
return []

@property
Expand Down
2 changes: 1 addition & 1 deletion sdcm/ndbench_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(self, *args, **kwargs):
self.stress_cmd = ' '.join([f'-Dndbench.config.{param.strip()}' for param in stress_cmd.split(';')])
timeout = '' if 'cli.timeoutMillis' in self.stress_cmd else f'-Dndbench.config.cli.timeoutMillis={self.timeout * 1000}'
self.stress_cmd = f'./gradlew {timeout}' \
f' -Dndbench.config.cass.host={self.node_list[0].cql_ip_address} {self.stress_cmd} run'
f' -Dndbench.config.cass.host={self.node_list[0].cql_address} {self.stress_cmd} run'

def _run_stress(self, loader, loader_idx, cpu_idx):
if not os.path.exists(loader.logdir):
Expand Down
2 changes: 1 addition & 1 deletion sdcm/nemesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4273,7 +4273,7 @@ def _add_new_node_in_new_dc(self) -> BaseNode:
with new_node.remote_scylla_yaml() as scylla_yml:
scylla_yml.rpc_address = new_node.ip_address
scylla_yml.seed_provider = [SeedProvider(class_name='org.apache.cassandra.locator.SimpleSeedProvider',
parameters=[{"seeds": self.tester.db_cluster.seed_nodes_ips}])]
parameters=[{"seeds": self.tester.db_cluster.seed_nodes_addresses}])]
endpoint_snitch = self.cluster.params.get("endpoint_snitch") or ""
if endpoint_snitch.endswith("GossipingPropertyFileSnitch"):
rackdc_value = {"dc": "add_remove_nemesis_dc"}
Expand Down
4 changes: 2 additions & 2 deletions sdcm/nosql_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def __init__(self, *args, **kwargs):

def build_stress_cmd(self, loader_idx: int):
if hasattr(self.node_list[0], 'parent_cluster'):
target_address = self.node_list[0].parent_cluster.get_node().cql_ip_address
target_address = self.node_list[0].parent_cluster.get_node().cql_address
else:
target_address = self.node_list[0].cql_ip_address
target_address = self.node_list[0].cql_address
with self._per_loader_count_lock:
threads_on_loader = self._per_loader_count.get(loader_idx, 0)
threads_on_loader += 1
Expand Down
2 changes: 1 addition & 1 deletion sdcm/provision/scylla_yaml/node_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ScyllaYamlNodeAttrBuilder(ScyllaYamlAttrBuilderBase):

@property
def _seed_address(self) -> str:
return ','.join(self.node.parent_cluster.seed_nodes_ips)
return ','.join(self.node.parent_cluster.seed_nodes_addresses)

@property
def _private_ip_address(self) -> str:
Expand Down
5 changes: 5 additions & 0 deletions sdcm/sct_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,11 @@ def __init__(self):
f"Simulating racks requires endpoint_snitch to be GossipingPropertyFileSnitch while it set to {self['endpoint_snitch']}"
self["endpoint_snitch"] = "org.apache.cassandra.locator.GossipingPropertyFileSnitch"

# 16 Validate use_dns_names
if self.get("use_dns_names"):
if cluster_backend not in ("aws",):
raise ValueError(f"use_dns_names is not supported for {cluster_backend} backend")

def log_config(self):
self.log.info(self.dump_config())

Expand Down
2 changes: 1 addition & 1 deletion sdcm/scylla_bench_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def create_stress_cmd(self, stress_cmd):
stress_cmd = f'{stress_cmd.strip()} -cloud-config-path={self.target_connection_bundle_file}'
else:
# Select first seed node to send the scylla-bench cmds
ips = ",".join([n.cql_ip_address for n in self.node_list])
ips = ",".join([n.cql_address for n in self.node_list])
stress_cmd = f'{stress_cmd.strip()} -nodes {ips}'

return stress_cmd
Expand Down
4 changes: 2 additions & 2 deletions sdcm/stress/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def db_node_to_query(self, loader):
assert db_nodes, "No node to query, nemesis runs on all DB nodes!"
node_to_query = random.choice(db_nodes)
LOGGER.debug("Selected '%s' to query for local nodes", node_to_query)
return node_to_query.cql_ip_address
return self.node_list[0].cql_ip_address
return node_to_query.cql_address
return self.node_list[0].cql_address

@property
def connection_bundle_file(self) -> Path:
Expand Down
2 changes: 1 addition & 1 deletion sdcm/stress_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def create_stress_cmd(self, cmd_runner, keyspace_idx, loader): # pylint: disabl
LOGGER.error("Not found datacenter for loader region '%s'. Datacenter per loader dict: %s",
loader.region, datacenter_name_per_region)

node_ip_list = [n.cql_ip_address for n in self.node_list]
node_ip_list = [n.cql_address for n in self.node_list]
stress_cmd += ",".join(node_ip_list)
if 'skip-unsupported-columns' in self._get_available_suboptions(cmd_runner, '-errors'):
stress_cmd = self._add_errors_option(stress_cmd, ['skip-unsupported-columns'])
Expand Down
10 changes: 9 additions & 1 deletion sdcm/utils/docker_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ def private_ip_address(self):
return self.internal_ip_address

@property
def cql_ip_address(self):
def cql_address(self):
return self.internal_ip_address

@property
def private_dns_name(self):
raise NotImplementedError()

@property
def public_dns_name(self) -> str:
raise NotImplementedError()

@cached_property
def running_in_docker(self):
ok = self.node.remoter.run("test /.dockerenv", ignore_status=True).ok
Expand Down
6 changes: 3 additions & 3 deletions sdcm/ycsb_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def copy_template(self, docker):
target_address = 'alternator'
else:
if hasattr(self.node_list[0], 'parent_cluster'):
target_address = self.node_list[0].parent_cluster.get_node().cql_ip_address
target_address = self.node_list[0].parent_cluster.get_node().cql_address
else:
target_address = self.node_list[0].cql_ip_address
target_address = self.node_list[0].cql_address

if 'dynamodb' in self.stress_cmd:
dynamodb_teample = dedent('''
Expand Down Expand Up @@ -168,7 +168,7 @@ def copy_template(self, docker):
docker.send_files(tmp_file.name, os.path.join('/tmp', 'aws_empty_file'))

def build_stress_cmd(self):
hosts = ",".join([i.cql_ip_address for i in self.node_list])
hosts = ",".join([i.cql_address for i in self.node_list])

stress_cmd = f'{self.stress_cmd} -s '
if 'dynamodb' in self.stress_cmd:
Expand Down
9 changes: 3 additions & 6 deletions test-cases/longevity/longevity-mini-test-1h.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_duration: 1000
stress_cmd: ["cassandra-stress write cl=QUORUM duration=900m -schema 'replication(strategy=NetworkTopologyStrategy,replication_factor=3)' -mode cql3 native -rate threads=2 -pop seq=1..10000000 -log interval=5"]
test_duration: 180
stress_cmd: ["cassandra-stress write cl=QUORUM duration=90m -schema 'replication(strategy=NetworkTopologyStrategy,replication_factor=3)' -mode cql3 native -rate threads=50 -pop seq=1..10000000 -log interval=5"]

n_db_nodes: 4
n_loaders: 1
Expand All @@ -9,11 +9,8 @@ instance_type_db: 'i4i.large'

nemesis_class_name: 'SisyphusMonkey'
nemesis_interval: 1
nemesis_multiply_factor: 1
use_dns_names: true


user_prefix: 'longevity-mini-test'
space_node_threshold: 6442

append_scylla_args: ' --blocked-reactor-notify-ms 25 --abort-on-lsa-bad-alloc 1 --abort-on-seastar-bad-alloc --abort-on-internal-error 1 --abort-on-ebadf 1 --enable-sstable-key-validation 1'
append_scylla_args: '--memory 4G --blocked-reactor-notify-ms 25 --abort-on-lsa-bad-alloc 1 --abort-on-seastar-bad-alloc --abort-on-internal-error 1 --abort-on-ebadf 1 --enable-sstable-key-validation 1'
2 changes: 1 addition & 1 deletion unit_tests/test_gemini_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, nodes):
self.nodes = nodes

def get_node_cql_ips(self):
return [node.cql_ip_address for node in self.nodes]
return [node.cql_address for node in self.nodes]


def test_01_gemini_thread(request, docker_scylla, params):
Expand Down
6 changes: 3 additions & 3 deletions unit_tests/test_scylla_yaml_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def is_builtin(inst):

# pylint: disable=too-few-public-methods
class FakeCluster:
seed_nodes_ips = ['1.1.1.1']
seed_nodes_addresses = ['1.1.1.1']


# pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -407,7 +407,7 @@ def __init__(self, params): # pylint: disable=super-init-not-called
self.name = 'dummy_cluster'

@property
def seed_nodes_ips(self):
def seed_nodes_addresses(self):
return [node.ip_address for node in self.nodes]

def init_nodes(self):
Expand Down Expand Up @@ -585,7 +585,7 @@ def _run_test(self, config_path: str, expected_node_config: str):
cluster.nodes.append(node)
cluster.nodes[0].is_seed = True
cluster.init_nodes()
seed_node_ips = ','.join(cluster.seed_nodes_ips)
seed_node_ips = ','.join(cluster.seed_nodes_addresses)
for node in cluster.nodes:
node.validate_scylla_yaml(expected_node_config=expected_node_config, seed_node_ips=seed_node_ips)
finally:
Expand Down
Loading

0 comments on commit 92f2e24

Please sign in to comment.