qontract-reconcile 0.10.1rc536__py3-none-any.whl → 0.10.1rc538__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,7 +90,7 @@ class TerraformClient: # pylint: disable=too-many-public-methods
90
90
  self.thread_pool_size = thread_pool_size
91
91
  self._aws_api = aws_api
92
92
  self._log_lock = Lock()
93
- self.should_apply = False
93
+ self.apply_count = 0
94
94
 
95
95
  self.specs: list[TerraformSpec] = []
96
96
  self.init_specs()
@@ -111,6 +111,12 @@ class TerraformClient: # pylint: disable=too-many-public-methods
111
111
  for account, output in self.outputs.items()
112
112
  }
113
113
 
114
+ def increment_apply_count(self):
115
+ self.apply_count += 1
116
+
117
+ def should_apply(self) -> bool:
118
+ return self.apply_count > 0
119
+
114
120
  def get_new_users(self):
115
121
  new_users = []
116
122
  self.init_outputs() # get updated output
@@ -282,7 +288,7 @@ class TerraformClient: # pylint: disable=too-many-public-methods
282
288
  after = output_change.get("after")
283
289
  if before != after:
284
290
  logging.info(["update", name, "output", output_name])
285
- self.should_apply = True
291
+ self.increment_apply_count()
286
292
 
287
293
  # A way to detect deleted outputs is by comparing
288
294
  # the prior state with the output changes.
@@ -295,7 +301,7 @@ class TerraformClient: # pylint: disable=too-many-public-methods
295
301
  deleted_outputs = [po for po in prior_outputs if po not in output_changes]
296
302
  for output_name in deleted_outputs:
297
303
  logging.info(["delete", name, "output", output_name])
298
- self.should_apply = True
304
+ self.increment_apply_count()
299
305
 
300
306
  resource_changes = output.get("resource_changes")
301
307
  if resource_changes is None:
@@ -339,7 +345,7 @@ class TerraformClient: # pylint: disable=too-many-public-methods
339
345
  resource_name,
340
346
  self._resource_diff_changed_fields(action, resource_change),
341
347
  ])
342
- self.should_apply = True
348
+ self.increment_apply_count()
343
349
  if action == "create":
344
350
  if resource_type == "aws_iam_user_login_profile":
345
351
  created_users.append(AccountUser(name, resource_name))
@@ -3890,22 +3890,30 @@ class TerrascriptClient: # pylint: disable=too-many-public-methods
3890
3890
  if os.path.isfile(print_to_file):
3891
3891
  os.remove(print_to_file)
3892
3892
 
3893
- for name, ts in self.tss.items():
3893
+ for name, ts in self.terraform_configurations().items():
3894
3894
  if print_to_file:
3895
3895
  with open(print_to_file, "a", encoding="locale") as f:
3896
3896
  f.write(f"##### {name} #####\n")
3897
- f.write(str(ts))
3897
+ f.write(ts)
3898
3898
  f.write("\n")
3899
3899
  if existing_dirs is None:
3900
3900
  wd = tempfile.mkdtemp(prefix=TMP_DIR_PREFIX)
3901
3901
  else:
3902
3902
  wd = working_dirs[name]
3903
3903
  with open(wd + "/config.tf.json", "w", encoding="locale") as f:
3904
- f.write(str(ts))
3904
+ f.write(ts)
3905
3905
  working_dirs[name] = wd
3906
3906
 
3907
3907
  return working_dirs
3908
3908
 
3909
+ def terraform_configurations(self) -> dict[str, str]:
3910
+ """
3911
+ Return the Terraform configurations (in JSON format) for each AWS account.
3912
+
3913
+ :return: key is AWS account name and value is terraform configuration
3914
+ """
3915
+ return {name: str(ts) for name, ts in self.tss.items()}
3916
+
3909
3917
  def init_values(self, spec: ExternalResourceSpec, init_tags: bool = True) -> dict:
3910
3918
  """
3911
3919
  Initialize the values of the terraform resource and merge the defaults and
tools/qontract_cli.py CHANGED
@@ -2446,8 +2446,8 @@ def early_exit_cache(ctx):
2446
2446
  )
2447
2447
  @click.option(
2448
2448
  "-c",
2449
- "--cache-desired-state",
2450
- help="Cache desired state. It should be a JSON string.",
2449
+ "--cache-source",
2450
+ help="Cache source. It should be a JSON string.",
2451
2451
  required=True,
2452
2452
  )
2453
2453
  @click.pass_context
@@ -2456,14 +2456,14 @@ def early_exit_cache_head(
2456
2456
  integration,
2457
2457
  integration_version,
2458
2458
  dry_run,
2459
- cache_desired_state,
2459
+ cache_source,
2460
2460
  ):
2461
2461
  with EarlyExitCache.build() as cache:
2462
2462
  cache_key = CacheKey(
2463
2463
  integration=integration,
2464
2464
  integration_version=integration_version,
2465
2465
  dry_run=dry_run,
2466
- cache_desired_state=json.loads(cache_desired_state),
2466
+ cache_source=json.loads(cache_source),
2467
2467
  )
2468
2468
  status = cache.head(cache_key)
2469
2469
  print(status)
@@ -2489,8 +2489,8 @@ def early_exit_cache_head(
2489
2489
  )
2490
2490
  @click.option(
2491
2491
  "-c",
2492
- "--cache-desired-state",
2493
- help="Cache desired state. It should be a JSON string.",
2492
+ "--cache-source",
2493
+ help="Cache source. It should be a JSON string.",
2494
2494
  required=True,
2495
2495
  )
2496
2496
  @click.pass_context
@@ -2499,14 +2499,14 @@ def early_exit_cache_get(
2499
2499
  integration,
2500
2500
  integration_version,
2501
2501
  dry_run,
2502
- cache_desired_state,
2502
+ cache_source,
2503
2503
  ):
2504
2504
  with EarlyExitCache.build() as cache:
2505
2505
  cache_key = CacheKey(
2506
2506
  integration=integration,
2507
2507
  integration_version=integration_version,
2508
2508
  dry_run=dry_run,
2509
- cache_desired_state=json.loads(cache_desired_state),
2509
+ cache_source=json.loads(cache_source),
2510
2510
  )
2511
2511
  value = cache.get(cache_key)
2512
2512
  print(value)
@@ -2532,14 +2532,14 @@ def early_exit_cache_get(
2532
2532
  )
2533
2533
  @click.option(
2534
2534
  "-c",
2535
- "--cache-desired-state",
2536
- help="Cache desired state. It should be a JSON string.",
2535
+ "--cache-source",
2536
+ help="Cache source. It should be a JSON string.",
2537
2537
  required=True,
2538
2538
  )
2539
2539
  @click.option(
2540
- "-d",
2541
- "--desired-state",
2542
- help="Desired state. It should be a JSON string.",
2540
+ "-p",
2541
+ "--payload",
2542
+ help="Payload in Cache value. It should be a JSON string.",
2543
2543
  required=True,
2544
2544
  )
2545
2545
  @click.option(
@@ -2568,8 +2568,8 @@ def early_exit_cache_set(
2568
2568
  integration,
2569
2569
  integration_version,
2570
2570
  dry_run,
2571
- cache_desired_state,
2572
- desired_state,
2571
+ cache_source,
2572
+ payload,
2573
2573
  log_output,
2574
2574
  applied_count,
2575
2575
  ttl,
@@ -2579,10 +2579,10 @@ def early_exit_cache_set(
2579
2579
  integration=integration,
2580
2580
  integration_version=integration_version,
2581
2581
  dry_run=dry_run,
2582
- cache_desired_state=json.loads(cache_desired_state),
2582
+ cache_source=json.loads(cache_source),
2583
2583
  )
2584
2584
  cache_value = CacheValue(
2585
- desired_state=json.loads(desired_state),
2585
+ payload=json.loads(payload),
2586
2586
  log_output=log_output,
2587
2587
  applied_count=applied_count,
2588
2588
  )
@@ -84,7 +84,7 @@ def test_early_exit_cache_set(env_vars, mock_queries, mock_early_exit_cache):
84
84
 
85
85
  result = runner.invoke(
86
86
  qontract_cli.early_exit_cache,
87
- "set -i a -v b --no-dry-run -c {} -d {} -l log -t 30",
87
+ "set -i a -v b --no-dry-run -c {} -p {} -l log -t 30",
88
88
  )
89
89
  assert result.exit_code == 0
90
90
  mock_early_exit_cache.build.return_value.__enter__.return_value.set.assert_called()