blib/lib/OcToolkit.pm

filter: Statementstmt 7.1% 61 / 849 Branchbran 0.0% 0 / 310 Conditioncond 0.0% 0 / 169 MC/DCmcdc 0.0% 0 / 89 Subroutinesub 30.7% 20 / 65 Podpod 38.4% 5 / 13 totaltotal 5.7% 86 / 1495 CC 269 SCAR 56.2
CC
269
Cov
5%
_getConfig
1122.0
_deleteUndefinedResourcesInCloud
756.0
_writeYamlFile
342.0
CRAP 276.2
↑ Summary
1 # John Summers, hereby disclaims all copyright interest in the program Open Cloud Toolkit aka "ocToolkit" written by John Summers
2 #
3 # John Summers, devp2000a@gmail.com
4 #
5 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8 #
9 # You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
10  
11 package OcToolkit;
12  
13 1 ▶use v5.16; # or newer
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = "1.21";
18  
19 1 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Text::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use File::Path qw(make_path rmtree);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use MIME::Base64 qw(encode_base64 decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use YAML qw(LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use YAML::Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34  
35 0 ▶sub new{
Subroutine new: not called CC=14 SCAR=53.5
Pod undocumented
36 0 my $class = shift;
37 0 my $self = {@_};
38
39 0 $self->{tt} = Template->new({INTERPOLATE => 1, ABSOLUTE => 1});
40 0 $self->{json} = JSON::PP->new;
41 0 $self->{json}->convert_blessed();
42
43 0 my $projectDir = $self->{projectDir}; # e.g.: /home/user/myProject/
44
45 0 ▶ $self->{secretsDir} = $projectDir."secrets" if not defined $self->{secretsDir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"secretsDir"} 0 0 0
46 0 ▶ $self->{secretsJson} = "secrets.json" if not defined $self->{secretsJson};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"secretsJson"} 0 0 0
47 0 ▶ $self->{octConfigFile} = $projectDir."oct_config.json" if not defined $self->{octConfigFile};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"octConfigFile"} 0 0 0
48 0 ▶ $self->{templatesTTDir} = $projectDir."templates_tt" if not defined $self->{templatesTTDir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"templatesTTDir"} 0 0 0
49 0 ▶ $self->{templatesYamlDir} = $projectDir."templates_yaml" if not defined $self->{templatesYamlDir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"templatesYamlDir"} 0 0 0
50 0 ▶ $self->{validationReportFile} = $projectDir."validation_report.txt" if not defined $self->{validationReportFile};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"validationReportFile"} 0 0 0
51 0 ▶ $self->{cloudCommand} = "oc" if not defined $self->{cloudCommand};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cloudCommand"} 0 0 0
52 0 ▶ if((defined $self->{advanceFeatures}) && ($self->{advanceFeatures} =~ /kubectl/)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /kubectl/u) 0 0 0
Condition0%0/3
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /kubectl/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /kubectl/u
defined $self->{"advanceFeatures"} $self->{"advanceFeatures"} =~ /kubectl/u
Truth table0%0/3
A and B
A= defined $self->{"advanceFeatures"}B= $self->{"advanceFeatures"} =~ /kubectl/u
ABresult
0X0
100
111
53 0 $self->{cloudCommand} = "kubectl";
54 }
55
56 0 ▶ if(!-e $self->{octConfigFile}){
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $self->{"octConfigFile"}) 0 0 0
57 0 ▶ open(my $fh, '>', $self->{octConfigFile}) or die "Could not create '$self->{octConfigFile}': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->{"octConfigFile"} or die qq[Could not create '$self->{"octConfigFile"}': $!] 0 0 0
58 0 print $fh '{}';
59 0 close($fh);
60 0 print "$self->{octConfigFile} is missing. Empty $self->{octConfigFile} is created.\n";
61 }
62  
63 0 ▶ if(not defined $self->{cluster}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"cluster"}) 0 0 0
64 0 my $octConfigFiletext = read_file($self->{octConfigFile});
65 0 my $octConfig = $self->{json}->utf8->decode($octConfigFiletext);
66 0 $self->{cluster} = $octConfig->{project}->{default_cluster};
67 0 ▶ $self->{cluster} = "unknown" if not defined $self->{cluster};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"cluster"} 0 0 0
68 }
69  
70 0 return bless $self, $class;
71 }
72  
73 0 ▶sub backup{
Subroutine backup: not called CC=1 SCAR=6.9
Pod documented
74 0 my ($self, $instance) = @_;
75  
76 0 $self->_initConfSecretsAndYaml($instance);
77  
78 0 $self->_createDir("backups");
79 0 $self->_createDir("backups\/$instance");
80
81 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "*", "_backupInstance");
82 0 $self->_runPostHook();
83
84 0 return;
85 }
86  
87 0 ▶sub backupWholeOCProject{
Subroutine backupWholeOCProject: not called CC=11 SCAR=48.8
Pod documented
88 0 my ($self) = @_;
89  
90 0 $self->_runPreHook();
91 0 $self->_createDir("backups");
92 0 $self->_createDir("backups\/wholeProject");
93 0 $self->_clearDir("backups/wholeProject");
94
95 0 my $octConfigFileText = read_file($self->{octConfigFile});
96 0 my $octConfig = $self->{json}->utf8->decode($octConfigFileText);
97
98 0 my $resourceKindsBackup = $octConfig->{project}->{resource_kinds_backup};
99 0 ▶ $resourceKindsBackup = $self->_getDefaultKindsBackup() if not defined $resourceKindsBackup;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $resourceKindsBackup 0 0 0
100 0 my @resourceKindsBackupArray = split(';', $resourceKindsBackup);
101
102 0 foreach my $octResourceKind (@resourceKindsBackupArray){
103 0 my $resourceKindsBackup = $octResourceKind;
104 0 ▶ if($octResourceKind ne "Ingress" &&
Branch: 1 branch
BranchTrueFalseTotal
if ($octResourceKind ne "Ingress" and $octResourceKind ne "StorageClass" and $octResourceKind ne "NetworkPolicy") 0 0 0
Condition0%0/6
$octResourceKind ne "Ingress" and $octResourceKind ne "StorageClass" and $octResourceKind ne "NetworkPolicy"
!ll&&!rl&&r
000
$octResourceKind ne "Ingress" and $octResourceKind ne "StorageClass"
!ll&&!rl&&r
000
MC/DC0%0/3
$octResourceKind ne "Ingress" and $octResourceKind ne "StorageClass" and $octResourceKind ne "NetworkPolicy"
$octResourceKind ne "Ingress" $octResourceKind ne "StorageClass" $octResourceKind ne "NetworkPolicy"
Truth table0%0/4
A and B and C
A= $octResourceKind ne "Ingress"B= $octResourceKind ne "StorageClass"C= $octResourceKind ne "NetworkPolicy"
ABCresult
0XX0
10X0
1100
1111
105 $octResourceKind ne "StorageClass" &&
106 $octResourceKind ne "NetworkPolicy"
107 ){
108 0 $resourceKindsBackup .= "s";
109 }
110 0 print "$resourceKindsBackup:\n";
111 0 my $text = qx/$self->{cloudCommand} get $resourceKindsBackup/;
112 0 my @textArray = split('\n', $text);
113 0 shift @textArray;
114 0 foreach my $line (@textArray){
115 0 my @lineArray = split(" ", $line);
116 0 my $octItem = $lineArray[0];
117 0 print "kind: $octResourceKind item: $octItem\n";
118 0 $self->_createDir("backups\/wholeProject\/$resourceKindsBackup");
119 0 eval {
120 0 my $octItemJson = qx/$self->{cloudCommand} get $octResourceKind $octItem -o json/;
121 0 my $octItemHash = $self->{json}->utf8->decode($octItemJson);
122 0 ▶ if((defined $self->{advanceFeatures}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u and defined $self->{"removeClutterBackup"}) 0 0 0
Condition0%0/6
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u and defined $self->{"removeClutterBackup"}
!ll&&!rl&&r
000
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u and defined $self->{"removeClutterBackup"}
defined $self->{"advanceFeatures"} $self->{"advanceFeatures"} =~ /removeClutter/u defined $self->{"removeClutterBackup"}
Truth table0%0/4
A and B and C
A= defined $self->{"advanceFeatures"}B= $self->{"advanceFeatures"} =~ /removeClutter/uC= defined $self->{"removeClutterBackup"}
ABCresult
0XX0
10X0
1100
1111
123 ($self->{advanceFeatures} =~ /removeClutter/) &&
124 (defined $self->{removeClutterBackup})){
125 0 my $subParams = {"octKind" => $octResourceKind, "octName" => $octItem};
126 0 $octItemHash = $self->{removeClutterBackup}->($octItemHash, $subParams);
127 }
128 0 my $yamlSaveObj = YAML::Safe->new->boolean("JSON::PP");
129 0 my $yamlText = $yamlSaveObj->Dump($octItemHash);
130 0 $yamlText =~ s/---\n//;
131 0 write_file("$self->{projectDir}backups\/wholeProject\/$resourceKindsBackup/$octItem".".yaml", $yamlText);
132 };
133 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
134 # if error occurred take yaml without calling '->removeClutterBackup()'
135 0 print "Removing clutter has failed, writing yaml file: $resourceKindsBackup/$octItem.yaml without removing clutter.\n";
136 0 my $yamlText = qx/$self->{cloudCommand} get $octResourceKind $octItem -o yaml/;
137 0 write_file("$self->{projectDir}backups\/wholeProject\/$resourceKindsBackup/$octItem".".yaml", $yamlText);
138 }
139 }
140 }
141 0 $self->_runPostHook();
142
143 0 return;
144 }
145  
146 0 ▶sub convertYamlToTTExtention{
Subroutine convertYamlToTTExtention: not called CC=1 SCAR=6.9
Pod undocumented
147 0 my ($self, $yamlToTTconvertDir) = @_;
148  
149 0 $self->_loopDir($yamlToTTconvertDir, "yaml", "_convertYamlToTTExtention",
150 {_convertYamlToTTExtention => {yamlToTTconvertDir => $yamlToTTconvertDir}});
151 }
152  
153 0 ▶sub delete{
Subroutine delete: not called CC=7 SCAR=40.3
Pod documented
154 0 my ($self, $instance) = @_;
155
156 0 $self->_initConfSecretsAndYaml($instance);
157  
158 0 my $cluster = $self->{config}->{cluster};
159 0 my $namespace = $self->{config}->{namespace};
160 0 ▶ return if ($self->{omit} // '') =~ /cloud/;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"omit"} // "") =~ /cloud/u 0 0 0
Condition0%0/2
$self->{"omit"} // ""
l!l
00
MC/DC0%0/1
$self->{"omit"} // ""
$self->{"omit"}
Truth table0%0/2
A
A= $self->{"omit"}
Aresult
11
00
161 0 ▶ return if not $self->_confirmOperation("Delete", $instance, $cluster, $namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_confirmOperation("Delete", $instance, $cluster, $namespace) 0 0 0
162
163 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "yaml", "_deleteFromCloud");
164
165 0 ▶ if((not $self->{config}->{oct_config}->{project}->{omit_deletion_of_not_defined_resources}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"config"}{"oct_config"}{"project"}{"omit_deletion_of_not_defined_resources"} and (defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /deleteUndefinedInCloud/u)) 0 0 0
Condition0%0/6
not $self->{"config"}{"oct_config"}{"project"}{"omit_deletion_of_not_defined_resources"} and (defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /deleteUndefinedInCloud/u)
!ll&&!rl&&r
000
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /deleteUndefinedInCloud/u
!ll&&!rl&&r
000
MC/DC0%0/3
not $self->{"config"}{"oct_config"}{"project"}{"omit_deletion_of_not_defined_resources"} and (defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /deleteUndefinedInCloud/u)
not $self->{"config"}{"oct_config"}{"project"}{"omit_deletion_of_not_defined_resources"} defined $self->{"advanceFeatures"} $self->{"advanceFeatures"} =~ /deleteUndefinedInCloud/u
Truth table0%0/4
not(A) and B and C
A= not $self->{"config"}{"oct_config"}{"project"}{"omit_deletion_of_not_defined_resources"}B= defined $self->{"advanceFeatures"}C= $self->{"advanceFeatures"} =~ /deleteUndefinedInCloud/u
ABCresult
0XX0
10X0
1100
1111
166 (defined $self->{advanceFeatures} && $self->{advanceFeatures} =~ /deleteUndefinedInCloud/)
167 ){
168 0 $self->_deleteUndefinedResourcesInCloud($instance);
169 }
170  
171 0 $self->_gitCommitAndPush();
172 0 $self->_runPostHook();
173
174 0 return;
175 }
176  
177 0 ▶sub generateConfigJsonTemplate{
Subroutine generateConfigJsonTemplate: not called CC=4 SCAR=30.0
Pod undocumented
178 0 my ($self, $instances) = @_;
179
180 0 print "Existing config file: $self->{octConfigFile} will be overwriten do you want to continue?
181 Press enter to contiue or type: 'skip' and press enter to skip this operation.\n";
182 0 my $continue = <>;
183 0 ▶ return if $continue =~ /skip/;
Branch: 1 branch
BranchTrueFalseTotal
if $continue =~ /skip/u 0 0 0
184
185 # preserve order in hash
186 0 my $componentFromTemplatesTTDir = $self->_getComponentsFromTemplatesTTDir();
187 0 $componentFromTemplatesTTDir =~ s/\-/_/g;
188 0 my @componentsArr = split(';', $componentFromTemplatesTTDir);
189 0 tie my %configHash, 'Tie::IxHash';
190 0 tie my %instanceSpecificData, 'Tie::IxHash';
191 0 $configHash{instance_specific_data} = \%instanceSpecificData;
192 0 foreach my $component (@componentsArr) {
193 0 tie my %componentHash, 'Tie::IxHash';
194 0 $instanceSpecificData{$component} = \%componentHash;
195 0 my @instancesArr = split(';', $instances);
196 0 foreach my $instance (@instancesArr) {
197 0 $componentHash{$instance} = {};
198 }
199 }
200 0 $configHash{instance_specific_name} = {};
201 0 $configHash{git_repo} = {};
202
203 0 tie my %gitHash, 'Tie::IxHash';
204 0 $gitHash{auto_commit} = 0;
205 0 $gitHash{auto_push} = 0;
206 0 $gitHash{auto_commit_prompt} = 0;
207 0 $gitHash{auto_push_branch} = "master";
208
209 0 tie my %projectHash, 'Tie::IxHash';
210 0 $projectHash{name} = "";
211 0 $projectHash{namespace} = undef;
212 0 $projectHash{host} = "";
213 0 $projectHash{default_cluster} = undef;
214 0 $projectHash{allowed_clusters} = undef;
215 0 $projectHash{component_dirs} = undef;
216 0 $projectHash{resource_kinds_backup} = undef;
217 0 $projectHash{resource_kinds} = undef;
218 0 $projectHash{git} = \%gitHash;
219 0 $projectHash{url_prefix} = undef;
220 0 $projectHash{prompt_write_operations} = 1;
221 0 $projectHash{default_cloud_write_command} = undef;
222 0 $projectHash{output_log_file} = "output.log";
223 0 $projectHash{omit_deletion_of_not_defined_resources} = undef;
224 0 $projectHash{revert_exemptions} = undef;
225 0 $projectHash{cluster_base_address} = undef;
226 0 $projectHash{cluster_ip_range} = "";
227
228 0 $configHash{project} = \%projectHash;
229
230 0 write_file($self->{octConfigFile}, $self->{json}->pretty->encode(\%configHash));
231  
232 0 return;
233 }
234  
235 0 ▶sub install{
Subroutine install: not called CC=4 SCAR=30.0
Pod documented
236 0 my ($self, $instance) = @_;
237  
238 0 $self->_initConfSecretsAndYaml($instance);
239  
240 0 my $cluster = $self->{config}->{cluster};
241 0 my $namespace = $self->{config}->{namespace};
242 0 ▶ return if ($self->{omit} // '') =~ /cloud/;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"omit"} // "") =~ /cloud/u 0 0 0
Condition0%0/2
$self->{"omit"} // ""
l!l
00
MC/DC0%0/1
$self->{"omit"} // ""
$self->{"omit"}
Truth table0%0/2
A
A= $self->{"omit"}
Aresult
11
00
243 0 ▶ return if not $self->_confirmOperation("Install", $instance, $cluster, $namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_confirmOperation("Install", $instance, $cluster, $namespace) 0 0 0
244  
245 # sent custom params
246 # $self->_loopDir($self->{config}->{templates_tt_dir}, "tt", "_callCloudCommand", {_callCloudCommand => {param1 => "value1", param2 => "value2"}});
247 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "yaml", "_callCloudCommand");
248 0 $self->_gitCommitAndPush();
249 0 $self->_runPostHook();
250
251 0 print qq^\n\nTo get build and deployment status run: $self->{cloudCommand} get pods --sort-by=.metadata.creationTimestamp | tac | grep Running\n\n^;
252
253 0 return;
254 }
255  
256 0 ▶sub revert{
Subroutine revert: not called CC=6 SCAR=37.4
Pod undocumented
257 0 my ($self, $instance) = @_;
258
259 # disable range narrowing, revert is meant to be used after 'git revert' or similar operation,
260 # whole project should be taken for revert
261 0 delete $self->{resourceKinds};
262 0 delete $self->{components};
263 0 delete $self->{specificYamlFile};
264
265 0 ▶ if(defined $self->{gitRevertHash}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"gitRevertHash"}) 0 0 0
266 0 print "git revert --no-commit $self->{gitRevertHash}..HEAD\n";
267 0 my $gitText = qx/git revert --no-commit $self->{gitRevertHash}..HEAD 2>&1/;
268 0 ▶ if($? != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) { } 0 0 0
269 0 print "Unable to git revert:\n$gitText\n";
270 0 return;
271 }else{
272 0 $self->_writeLog($gitText);
273 }
274 }
275
276 0 my $skipPostHooks = 1;
277 0 my $skipGitCommit = 1;
278 0 my $atLeastOneUpdated = $self->update($instance, $skipPostHooks, $skipGitCommit);
279  
280 0 my $atLeastOneDeleted = 0;
281 0 ▶ if(not $self->{config}->{oct_config}->{project}->{omit_deletion_of_not_defined_resources}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"oct_config"}{"project"}{"omit_deletion_of_not_defined_resources"}) 0 0 0
282 0 $atLeastOneDeleted = $self->_deleteUndefinedResourcesInCloud($instance);
283 }
284 0 ▶ $self->_gitCommitAndPush() if $atLeastOneUpdated || $atLeastOneDeleted;
Branch: 1 branch
BranchTrueFalseTotal
if $atLeastOneUpdated or $atLeastOneDeleted 0 0 0
Condition0%0/3
$atLeastOneUpdated or $atLeastOneDeleted
l!l&&r!l&&!r
000
MC/DC0%0/2
$atLeastOneUpdated or $atLeastOneDeleted
$atLeastOneUpdated $atLeastOneDeleted
Truth table0%0/3
A or B
A= $atLeastOneUpdatedB= $atLeastOneDeleted
ABresult
1X1
011
000
285
286 0 $self->_runPostHook();
287
288 0 return;
289 }
290  
291 0 ▶sub setParams{
Subroutine setParams: not called CC=4 SCAR=30.0
Pod undocumented
292 0 my ($self, $params) = @_;
293
294 0 ▶ if(@_ == 2){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 0 0 0
295 0 for my $key (keys %$params){
296 0 ▶ $self->{$key} = $params->{$key} if defined $params->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{$key} 0 0 0
297 }
298 }
299  
300 0 return;
301 }
302  
303 0 ▶sub scaleToZero{
Subroutine scaleToZero: not called CC=4 SCAR=30.0
Pod undocumented
304 0 my ($self, $instance) = @_;
305  
306 0 $self->_initConfSecretsAndYaml($instance);
307  
308 0 foreach my $resourceName (keys %{$self->{templateManifests}->{Deployment}}){
309 0 print "$self->{cloudCommand} scale Deployment $resourceName --replicas=0\n";
310 0 qx/$self->{cloudCommand} scale Deployment $resourceName --replicas=0/;
311 }
312 0 foreach my $resourceName (keys %{$self->{templateManifests}->{DeploymentConfig}}){
313 0 print "$self->{cloudCommand} scale DeploymentConfig $resourceName --replicas=0\n";
314 0 qx/$self->{cloudCommand} scale DeploymentConfig $resourceName --replicas=0/;
315 }
316 0 foreach my $resourceName (keys %{$self->{templateManifests}->{StatefulSet}}){
317 0 print "$self->{cloudCommand} scale StatefulSet $resourceName --replicas=0\n";
318 0 qx/$self->{cloudCommand} scale StatefulSet $resourceName --replicas=0/;
319 }
320  
321 0 return;
322 }
323  
324 0 ▶sub update{
Subroutine update: not called CC=12 SCAR=50.5
Pod documented
325 0 my ($self, $instance, $skipPostHooks, $skipGitCommit) = @_;
326
327 0 $self->validateAgainstCloud($instance, $skipPostHooks);
328  
329 0 ▶ if(not $self->{atLeastOneModified}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"atLeastOneModified"}) 0 0 0
330 0 print "No updated needed.\n";
331 0 return;
332 }
333
334 0 my $cluster = $self->{config}->{cluster};
335 0 my $namespace = $self->{config}->{namespace};
336 0 ▶ return if ($self->{omit} // '') =~ /cloud/;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"omit"} // "") =~ /cloud/u 0 0 0
Condition0%0/2
$self->{"omit"} // ""
l!l
00
MC/DC0%0/1
$self->{"omit"} // ""
$self->{"omit"}
Truth table0%0/2
A
A= $self->{"omit"}
Aresult
11
00
337 0 ▶ return if not $self->_confirmOperation("Update", $instance, $cluster, $namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_confirmOperation("Update", $instance, $cluster, $namespace) 0 0 0
338
339 0 my $validationReport = read_file($self->{validationReportFile});
340 0 my @validationReportLines = split /\n/, $validationReport;
341 0 my $atLeastOneUpdated = 0;
342 0 foreach my $line (@validationReportLines){
343 0 my @items = split /;/, $line;
344 0 ▶ if($items[-1] eq "MODIFIED"){
Branch: 1 branch
BranchTrueFalseTotal
if ($items[-1] eq "MODIFIED") 0 0 0
345 0 $atLeastOneUpdated = 1;
346 0 my $pathAndFile = $items[0];
347 0 my $octKind = $items[1];
348 0 my $octName = $items[2];
349 0 ▶ if($octKind eq "PersistentVolumeClaim"){
Branch: 1 branch
BranchTrueFalseTotal
if ($octKind eq "PersistentVolumeClaim") 0 0 0
350 0 my $text = "You are trying to update PersistentVolumeClaim.
351 Please make sure that all PODs that use this Persisten Volume are turned down before update.
352 If update operation start hanging at this step press ctrl+c to abort. \n\n";
353 0 $self->_writeLog($text);
354 }
355 0 $self->_writeLog("Updating octKind:$octKind, octName: $octName from $pathAndFile\n");
356 0 my $writeCommand = $self->_getCloudWriteCommand();
357 0 my $outputText = "";
358 0 ▶ $outputText = qx/$self->{cloudCommand} delete $octKind $octName 2>&1/ if $writeCommand eq "create";
Branch: 1 branch
BranchTrueFalseTotal
if $writeCommand eq "create" 0 0 0
359 0 $self->_writeLog($outputText);
360 0 my $templatesYamlDir = $self->{config}->{templates_yaml_dir};
361 0 $outputText = qx/$self->{cloudCommand} $writeCommand -f $templatesYamlDir\/$pathAndFile 2>&1/;
362 0 $self->_writeLog($outputText);
363 }
364 }
365 0 ▶ $self->_gitCommitAndPush() if $atLeastOneUpdated && (not $skipGitCommit);
Branch: 1 branch
BranchTrueFalseTotal
if $atLeastOneUpdated and not $skipGitCommit 0 0 0
Condition0%0/3
$atLeastOneUpdated and not $skipGitCommit
!ll&&!rl&&r
000
MC/DC0%0/2
$atLeastOneUpdated and not $skipGitCommit
$atLeastOneUpdated not $skipGitCommit
Truth table0%0/3
A and not(B)
A= $atLeastOneUpdatedB= not $skipGitCommit
ABresult
0X0
100
111
366 0 ▶ $self->_runPostHook() if not defined $skipPostHooks;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skipPostHooks 0 0 0
367
368 0 return $atLeastOneUpdated;
369 }
370  
371 0 ▶sub validateAgainstCloud{
Subroutine validateAgainstCloud: not called CC=2 SCAR=17.9
Pod undocumented
372 0 my ($self, $instance, $skipPostHooks) = @_;
373  
374 0 qx/> $self->{validationReportFile}/; # clear file
375
376 0 $self->_initConfSecretsAndYaml($instance);
377
378 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "yaml", "_validateAgainstCloud");
379 0 ▶ $self->_runPostHook() if not defined $skipPostHooks;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skipPostHooks 0 0 0
380
381 0 return;
382 }
383  
384 0 ▶sub validateManifests{
Subroutine validateManifests: not called CC=2 SCAR=17.9
Pod undocumented
385 0 my ($self, $instance, $skipPostHooks) = @_;
386
387 0 $self->_initConfSecretsAndYaml($instance);
388 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "yaml", "_callCloudCommand", {_callCloudCommand => {dryRun => 1}});
389 0 ▶ $self->_runPostHook() if not defined $skipPostHooks;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skipPostHooks 0 0 0
390
391 0 return;
392 }
393  
394 0 ▶sub _addSecretsToConfigHash{
Subroutine _addSecretsToConfigHash: not called CC=1 SCAR=6.9
395 0 my ($self, $config, $dirFileName) = @_;
396  
397 0 my @dirFileNameArr = split('/', $dirFileName); # test, prod etc.
398 0 my $secretText = read_file($dirFileName);
399 0 $config->{secrets}->{$dirFileNameArr[-1]} = $secretText;
400
401 0 my $secretTextBase64 = encode_base64($secretText, "");
402 0 $config->{secrets}->{base64}->{$dirFileNameArr[-1]} = $secretTextBase64;
403  
404 0 return;
405 }
406  
407 0 ▶sub _backupInstance{
Subroutine _backupInstance: not called CC=4 SCAR=30.0
408 0 my ($self, $params) = @_;
409  
410 0 my $dir = $params->{dir};
411 0 my $templateName = $params->{templateName};
412  
413 0 my $instance = $self->{config}->{instance};
414 0 $self->_createDir("backups\/$instance\/$dir");
415 0 my $pathToYamlFile = "$self->{config}->{templates_yaml_dir}/$dir/$templateName".".yaml";
416 0 my $templateData = LoadFile($pathToYamlFile);
417
418 0 my $yamlText;
419 0 ▶ if((defined $self->{advanceFeatures}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'advanceFeatures'} and $self->{'advanceFeatures'} =~ /removeClutter/u and defined $self->{'removeClutterBackup'}) { } 0 0 0
Condition0%0/6
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u and defined $self->{"removeClutterBackup"}
!ll&&!rl&&r
000
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /removeClutter/u and defined $self->{"removeClutterBackup"}
defined $self->{"advanceFeatures"} $self->{"advanceFeatures"} =~ /removeClutter/u defined $self->{"removeClutterBackup"}
Truth table0%0/4
A and B and C
A= defined $self->{"advanceFeatures"}B= $self->{"advanceFeatures"} =~ /removeClutter/uC= defined $self->{"removeClutterBackup"}
ABCresult
0XX0
10X0
1100
1111
420 ($self->{advanceFeatures} =~ /removeClutter/) &&
421 (defined $self->{removeClutterBackup})){
422 0 print "$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o json\n";
423 0 my $octJson = qx/$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o json/;
424 0 my $octHash = $self->{json}->utf8->decode($octJson);
425 0 my $subParams = {"octKind" => $templateData->{kind}, "octName" => $templateData->{metadata}->{name}};
426 0 $octHash = $self->{removeClutterBackup}->($octHash, $subParams);
427 0 my $yamlSaveObj = YAML::Safe->new->boolean("JSON::PP");
428 0 $yamlText = $yamlSaveObj->Dump($octHash);
429 0 $yamlText =~ s/---\n//;
430 }else{
431 0 print "$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o yaml\n";
432 0 $yamlText = qx/$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o yaml/;
433 }
434  
435 0 write_file("$self->{projectDir}backups\/$instance\/$dir/$templateName".".yaml", $yamlText);
436 }
437  
438 0 ▶sub _callCloudCommand{
Subroutine _callCloudCommand: not called CC=7 SCAR=40.3
439 0 my ($self, $params) = @_;
440
441 0 my @funcName = split /::/, (caller(0))[3];
442 0 my $dir = $params->{dir};
443 0 my $templateName = $params->{templateName};
444 0 my $customParams = $params->{params}->{$funcName[-1]};
445  
446 return if (defined $self->{componentIsAllowed}) &&
447 0 ▶ (not $self->{componentIsAllowed}->($templateName, $dir, $self->{config}->{cluster}, $self->{instance}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"componentIsAllowed"} and not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"}) 0 0 0
Condition0%0/3
defined $self->{"componentIsAllowed"} and not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"componentIsAllowed"} and not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
defined $self->{"componentIsAllowed"} not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
Truth table0%0/3
A and not(B)
A= defined $self->{"componentIsAllowed"}B= not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
ABresult
0X0
100
111
448  
449 0 my $templateNameYaml = $templateName.".yaml";
450 0 my $pathAndFile = $self->{config}->{templates_yaml_dir}."\/$dir\/$templateNameYaml";
451 0 my $yamlData = LoadFile($pathAndFile);
452  
453 0 ▶ if(not defined $customParams->{dryRun}){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $customParams->{'dryRun'}) { } 0 0 0
454 0 my $writeCommand = $self->_getCloudWriteCommand();
455 0 $self->_writeLog("$self->{cloudCommand} $writeCommand -f $pathAndFile\n");
456 0 my $outputText = qx/$self->{cloudCommand} $writeCommand -f $pathAndFile 2>&1/;
457 0 $self->_writeLog($outputText);
458 }else{
459 0 my $infoText = "$dir\/$templateNameYaml";
460 0 my $text = qx/$self->{cloudCommand} apply --dry-run=server --validate=true -f $pathAndFile 2>&1/;
461 0 my $isError = $? >> 8;
462 0 ▶ if($isError){
Branch: 1 branch
BranchTrueFalseTotal
if ($isError) { } 0 0 0
463 0 ▶ $text = $self->{ignoreManifestValidationErrors}->($text) if defined $self->{ignoreManifestValidationErrors};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ignoreManifestValidationErrors"} 0 0 0
464 0 ▶ if($text ne ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($text ne '') { } 0 0 0
465 0 print "$infoText ERROR\n";
466 0 print "============\n$text\n============\n";
467 }else{
468 # ignore this error
469 0 print "$infoText OK\n";
470 }
471 }else{
472 0 print "$infoText;OK\n";
473 }
474 }
475
476 0 return;
477 }
478  
479 0 ▶sub _clearDir{
Subroutine _clearDir: not called CC=1 SCAR=6.9
480 0 my ($self, $dir) = @_;
481  
482 0 rmtree $dir;
483 0 make_path $dir;
484 }
485  
486 0 ▶sub _confirmOperation{
Subroutine _confirmOperation: not called CC=12 SCAR=50.5
487 0 my ($self, $type, $instance, $cluster, $namespace) = @_;
488
489 0 ▶ return if ($self->{omit} // '') =~ /confirm/;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"omit"} // "") =~ /confirm/u 0 0 0
Condition0%0/2
$self->{"omit"} // ""
l!l
00
MC/DC0%0/1
$self->{"omit"} // ""
$self->{"omit"}
Truth table0%0/2
A
A= $self->{"omit"}
Aresult
11
00
490
491 0 $self->_writeLog(qx/oc project/);
492
493 0 my $components;
494 0 ▶ if(($self->{omit} // '') =~ /init/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (($self->{'omit'} // '') =~ /init/u) { } 0 0 0
Condition0%0/2
$self->{"omit"} // ""
l!l
00
MC/DC0%0/1
$self->{"omit"} // ""
$self->{"omit"}
Truth table0%0/2
A
A= $self->{"omit"}
Aresult
11
00
495 0 $components = $self->{config}->{standard_component_dirs};
496 }else{
497 0 $components = $self->{config}->{component_dirs};
498 }
499 0 ▶ $components = "all" if not defined $components;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $components 0 0 0
500 0 my $preposition = "for";
501 0 ▶ $preposition = "from" if $type eq "Delete";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Delete" 0 0 0
502 0 my $componentsText = "\nCOMPONENT(S): '$components' $preposition";
503
504 0 my $confirmOperationText = "";
505 0 ▶ if(defined $self->{specificYamlFile}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"specificYamlFile"}) 0 0 0
506 0 $confirmOperationText = "\nFILE NAME CONTAINS:'$self->{specificYamlFile}' in";
507 }
508
509 0 ▶ if(defined $self->{resourceKinds}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"resourceKinds"}) 0 0 0
510 0 $confirmOperationText .= "\nKIND(s): '$self->{resourceKinds}' in";
511 }
512
513 0 my $continue = "";
514 0 my $infoText = "\n$type $confirmOperationText $componentsText\nINSTANCE: '$instance' in\nNAMESPACE: '$namespace' in\nCLUSTER: '$cluster'\n";
515 0 $self->_writeLog($infoText);
516 0 ▶ if(($self->{omit} // '') !~ /cloud/ && $self->{config}->{oct_config}->{project}->{prompt_write_operations}){
Branch: 1 branch
BranchTrueFalseTotal
if (not +($self->{"omit"} // "") =~ /cloud/u and $self->{"config"}{"oct_config"}{"project"}{"prompt_write_operations"}) 0 0 0
Condition0%0/5
not +($self->{"omit"} // "") =~ /cloud/u and $self->{"config"}{"oct_config"}{"project"}{"prompt_write_operations"}
!ll&&!rl&&r
000
$self->{"omit"} // ""
l!l
00
MC/DC0%0/2
not +($self->{"omit"} // "") =~ /cloud/u and $self->{"config"}{"oct_config"}{"project"}{"prompt_write_operations"}
$self->{"omit"} $self->{"config"}{"oct_config"}{"project"}{"prompt_write_operations"}
Truth table0%0/3
not(A) and B
A= $self->{"omit"}B= $self->{"config"}{"oct_config"}{"project"}{"prompt_write_operations"}
ABresult
1X0
000
011
517 0 $self->_writeLog("Press enter to continue or type: 'skip' and press enter to skip this operation.\n");
518 0 $continue = <>;
519 }
520
521 0 return $continue !~ /skip/;
522 }
523  
524 0 ▶sub _convertYamlToTTExtention{
Subroutine _convertYamlToTTExtention: not called CC=1 SCAR=6.9
525 0 my ($self, $params) = @_;
526  
527 0 my @funcName = split /::/, (caller(0))[3];
528 0 my $dir = $params->{dir};
529 0 my $templateName = $params->{templateName};
530 0 my $customParams = $params->{params}->{$funcName[-1]};
531 0 my $yamlToTTconvertDir = $customParams->{yamlToTTconvertDir};
532
533 0 my $path = "$yamlToTTconvertDir/$dir";
534 0 qx/mv $path\/$templateName\.yaml $path\/$templateName\.tt 2>&1/;
535 }
536  
537 0 ▶sub _createTemplatesTTDirHash{
Subroutine _createTemplatesTTDirHash: not called CC=9 SCAR=45.0
538 0 my ($self, $params) = @_;
539
540 0 my $dir = $params->{dir};
541 0 my $templateName = $params->{templateName};
542  
543 # $self->{templatesTTHash}->{"40-api"}->{"40-build-config-api"} = "40-api/clusterIntern/40-build-config-api";
544 # $self->{templatesTTHash}->{"40-api"}->{"45-build-config-api"} = "40-api/test/40-build-config-api";
545 # $self->{templatesTTHash}->{"40-api"}->{"46-build-config-api"} = "40-api/clusterPublic/instance/prod/40-build-config-api";
546 0 ▶ if(not -d "$self->{templatesTTDir}/$dir/$templateName"){
Branch: 3 branches
BranchTrueFalseTotal
if (not -d "$self->{'templatesTTDir'}/$dir/$templateName") { } 0 0 0
elsif ($templateName eq $self->{'config'}{'cluster'}) { } 0 0 0
elsif ($templateName eq 'instance' and -d "$self->{'templatesTTDir'}/$dir/instance/$self->{'config'}{'instance'}") { } 0 0 0
547 0 $self->{templatesTTHash}->{$dir}->{$templateName} = "$dir/$templateName";
548 }elsif($templateName eq $self->{config}->{cluster}){
549 0 for my $dirFileName (File::Find::Rule
550 ->file()
551 ->name("*")
552 ->maxdepth(1)
553 ->in("$self->{templatesTTDir}/$dir/$self->{config}->{cluster}")){
554 0 my @dirFileNameArr = split('/', $dirFileName);
555 0 my $templName = substr($dirFileNameArr[-1], 0, -3);
556 0 $self->{templatesTTHash}->{$dir}->{$templName} = "$dir/$self->{config}->{cluster}/$templName";
557 }
558 0 ▶ if(-d "$self->{templatesTTDir}/$dir/$self->{config}->{cluster}/instance/$self->{config}->{instance}"){
Branch: 1 branch
BranchTrueFalseTotal
if (-d qq[$self->{"templatesTTDir"}/$dir/$self->{"config"}{"cluster"}/instance/$self->{"config"}{"instance"}]) 0 0 0
559 0 for my $dirFileName (File::Find::Rule
560 ->file()
561 ->name("*")
562 ->maxdepth(1)
563 ->in("$self->{templatesTTDir}/$dir/$self->{config}->{cluster}/instance/$self->{config}->{instance}")){
564 0 my @dirFileNameArr = split('/', $dirFileName);
565 0 my $templName = substr($dirFileNameArr[-1], 0, -3);
566 0 $self->{templatesTTHash}->{$dir}->{$templName} =
567 "$dir/$self->{config}->{cluster}/instance/$self->{config}->{instance}/$templName";
568 }
569 }
570 ▶ }elsif(($templateName eq "instance") && (-d "$self->{templatesTTDir}/$dir/instance/$self->{config}->{instance}")){
Condition0%0/3
$templateName eq "instance" and -d qq[$self->{"templatesTTDir"}/$dir/instance/$self->{"config"}{"instance"}]
!ll&&!rl&&r
000
MC/DC0%0/2
$templateName eq "instance" and -d qq[$self->{"templatesTTDir"}/$dir/instance/$self->{"config"}{"instance"}]
$templateName eq "instance" -d qq[$self->{"templatesTTDir"}/$dir/instance/$self->{"config"}{"instance"}]
Truth table0%0/3
A and B
A= $templateName eq "instance"B= -d qq[$self->{"templatesTTDir"}/$dir/instance/$self->{"config"}{"instance"}]
ABresult
0X0
100
111
571 0 for my $dirFileName (File::Find::Rule
572 ->file()
573 ->name("*")
574 ->maxdepth(1)
575 ->in("$self->{templatesTTDir}/$dir/instance/$self->{config}->{instance}")){
576 0 my @dirFileNameArr = split('/', $dirFileName);
577 0 my $templName = substr($dirFileNameArr[-1], 0, -3);
578 0 $self->{templatesTTHash}->{$dir}->{$templName} = "$dir/instance/$self->{config}->{instance}/$templName";
579 }
580 }
581  
582 0 return;
583 }
584  
585 0 ▶sub _createDir{
Subroutine _createDir: not called CC=1 SCAR=6.9
586 0 my ($self, $relativeDirPath) = @_;
587 0 qx/mkdir $self->{projectDir}$relativeDirPath 2>&1/;
588 0 return;
589 }
590  
591 0 ▶sub _deleteFromCloud{
Subroutine _deleteFromCloud: not called CC=1 SCAR=6.9
592 0 my ($self, $params) = @_;
593  
594 0 my $dir = $params->{dir};
595 0 my $templateName = $params->{templateName};
596  
597 0 my $data = LoadFile("$self->{config}->{templates_yaml_dir}/$dir/$templateName".".yaml");
598 0 $self->_writeLog("$self->{cloudCommand} delete $data->{kind} $data->{metadata}->{name}\n");
599 0 my $outputText = qx/$self->{cloudCommand} delete $data->{kind} $data->{metadata}->{name} 2>&1/;
600 0 $self->_writeLog($outputText);
601
602 0 return;
603 }
604  
605 0 ▶sub _deleteUndefinedResourcesInCloud{
Subroutine _deleteUndefinedResourcesInCloud: not called CC=27 SCAR=66.3
606 0 my ($self, $instance) = @_;
607
608 # get $self->{templateManifests} for all instances in current cluster
609 0 my $allClusterInstances;
610 0 my $cluster = $self->{config}->{cluster};
611 0 my $confingProject = $self->{config}->{oct_config}->{project};
612 0 ▶ if(defined $confingProject->{git} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $confingProject->{"git"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}{$cluster}) 0 0 0
Condition0%0/6
defined $confingProject->{"git"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}{$cluster}
!ll&&!rl&&r
000
defined $confingProject->{"git"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $confingProject->{"git"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"} and defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}{$cluster}
defined $confingProject->{"git"} defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"} defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}{$cluster}
Truth table0%0/4
A and B and C
A= defined $confingProject->{"git"}B= defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}C= defined $confingProject->{"git"}{"revert_multiple_instances_in_same_project"}{$cluster}
ABCresult
0XX0
10X0
1100
1111
613 defined $confingProject->{git}->{revert_multiple_instances_in_same_project} &&
614 defined $confingProject->{git}->{revert_multiple_instances_in_same_project}->{$cluster}
615 ){
616 0 $allClusterInstances = dclone($confingProject->{git}->{revert_multiple_instances_in_same_project}->{$cluster});
617 # remove current instance, it is already processed
618 0 @$allClusterInstances = grep { $_ ne $instance } @$allClusterInstances;
619
620 0 foreach my $cInstance (@$allClusterInstances){
621 0 $self->{instance} = $cInstance;
622 0 $self->{config} = $self->_getConfig();
623 0 $self->_generateYaml();
624 }
625 # bring back current instace to 'template_yaml'
626 0 $self->{instance} = $instance;
627 0 $self->{config} = $self->_getConfig();
628 0 $self->_generateYaml();
629 }
630
631 0 my $resourceKinds = $self->{config}->{resource_kinds};
632 0 my @resourceKindsArr = split(';', $resourceKinds);
633
634 # get resources from Cloud
635 0 my $cloudVsManifestDiff;
636 0 foreach my $resourceKind (@resourceKindsArr){
637 0 my $text = qx/$self->{cloudCommand} get $resourceKind/;
638 0 my @textArr = split("\n", $text);
639 0 shift @textArr;
640 0 foreach my $textLine (@textArr){
641 0 my ($resourceName) = split /\s+/, $textLine =~ s/^\s+//r; # remove also leading spaces
642 0 $cloudVsManifestDiff->{$resourceKind}->{$resourceName} = 1;
643 }
644 }
645  
646 0 my @revertExemptionsArr = ();
647 0 my $revertExemptions = $self->{config}->{oct_config}->{project}->{revert_exemptions};
648 0 ▶ @revertExemptionsArr = split(';', $revertExemptions) if defined $revertExemptions;
Branch: 1 branch
BranchTrueFalseTotal
if defined $revertExemptions 0 0 0
649
650 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
651 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
652 0 foreach my $revertExemption (@revertExemptionsArr){
653 0 ▶ if($resourceName =~ /$revertExemption/){
Branch: 1 branch
BranchTrueFalseTotal
if ($resourceName =~ /$revertExemption/u) 0 0 0
654 # don't delete this resource, remove him from template manifests vs cloud resources difference hash
655 0 delete $cloudVsManifestDiff->{$resourceKind}->{$resourceName};
656 }
657 }
658 0 ▶ if((defined $self->{templateManifests}) && $self->{templateManifests}->{$resourceKind}->{$resourceName}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"templateManifests"} and $self->{"templateManifests"}{$resourceKind}{$resourceName}) 0 0 0
Condition0%0/3
defined $self->{"templateManifests"} and $self->{"templateManifests"}{$resourceKind}{$resourceName}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"templateManifests"} and $self->{"templateManifests"}{$resourceKind}{$resourceName}
defined $self->{"templateManifests"} $self->{"templateManifests"}{$resourceKind}{$resourceName}
Truth table0%0/3
A and B
A= defined $self->{"templateManifests"}B= $self->{"templateManifests"}{$resourceKind}{$resourceName}
ABresult
0X0
100
111
659 0 delete $cloudVsManifestDiff->{$resourceKind}->{$resourceName};
660 }
661 }
662 }
663  
664 0 my $cloudVsManifestDiffIsEmpty = 1;
665 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
666 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
667 0 ▶ if((defined $cloudVsManifestDiff->{$resourceKind}) && $cloudVsManifestDiff->{$resourceKind}->{$resourceName}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cloudVsManifestDiff->{$resourceKind} and $cloudVsManifestDiff->{$resourceKind}{$resourceName}) 0 0 0
Condition0%0/3
defined $cloudVsManifestDiff->{$resourceKind} and $cloudVsManifestDiff->{$resourceKind}{$resourceName}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cloudVsManifestDiff->{$resourceKind} and $cloudVsManifestDiff->{$resourceKind}{$resourceName}
defined $cloudVsManifestDiff->{$resourceKind} $cloudVsManifestDiff->{$resourceKind}{$resourceName}
Truth table0%0/3
A and B
A= defined $cloudVsManifestDiff->{$resourceKind}B= $cloudVsManifestDiff->{$resourceKind}{$resourceName}
ABresult
0X0
100
111
668 0 $cloudVsManifestDiffIsEmpty = 0;
669 }
670 }
671 }
672
673 0 my $atLeastOneDeleted = 0;
674 0 ▶ if(not $cloudVsManifestDiffIsEmpty){
Branch: 1 branch
BranchTrueFalseTotal
unless ($cloudVsManifestDiffIsEmpty) 0 0 0
675 0 $self->_writeLog("\nThis resources are not defined in Manifests but they are found in Cloud:\n");
676 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
677 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
678 0 $self->_writeLog(sprintf "Resource kind: %-25s Resource name: %s\n", $resourceKind, $resourceName);
679 }
680 }
681 0 my $continue = "";
682 0 ▶ if($self->{config}->{oct_config}->{project}->{prompt_write_operations}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"oct_config"}{"project"}{"prompt_write_operations"}) 0 0 0
683 0 $self->_writeLog("\nPress enter to delete them or type 'skip' and press enter to keep them:\n");
684 0 $continue = <>;
685 }
686 0 ▶ if($continue !~ /skip/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($continue =~ /skip/u) 0 0 0
687 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
688 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
689 0 ▶ if((defined $cloudVsManifestDiff->{$resourceKind}) && $cloudVsManifestDiff->{$resourceKind}->{$resourceName}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cloudVsManifestDiff->{$resourceKind} and $cloudVsManifestDiff->{$resourceKind}{$resourceName}) 0 0 0
Condition0%0/3
defined $cloudVsManifestDiff->{$resourceKind} and $cloudVsManifestDiff->{$resourceKind}{$resourceName}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cloudVsManifestDiff->{$resourceKind} and $cloudVsManifestDiff->{$resourceKind}{$resourceName}
defined $cloudVsManifestDiff->{$resourceKind} $cloudVsManifestDiff->{$resourceKind}{$resourceName}
Truth table0%0/3
A and B
A= defined $cloudVsManifestDiff->{$resourceKind}B= $cloudVsManifestDiff->{$resourceKind}{$resourceName}
ABresult
0X0
100
111
690 0 $atLeastOneDeleted = 1;
691 0 $self->_writeLog("$self->{cloudCommand} delete $resourceKind $resourceName\n");
692 0 my $outputText = qx/$self->{cloudCommand} delete $resourceKind $resourceName 2>&1/;
693 0 $self->_writeLog($outputText);
694 }
695 }
696 }
697 }
698 }
699  
700 0 return $atLeastOneDeleted;
701 }
702  
703 0 ▶sub _encodeJsonHashToBase64{
Subroutine _encodeJsonHashToBase64: not called CC=6 SCAR=37.4
704 0 my ($self, $jsonHash) = @_;
705  
706 0 ▶ if(ref $jsonHash eq 'HASH'){
Branch: 3 branches
BranchTrueFalseTotal
if (ref $jsonHash eq 'HASH') { } 0 0 0
elsif (ref $jsonHash eq 'ARRAY') { } 0 0 0
elsif (defined $jsonHash) { } 0 0 0
707 0 $_ = $self->_encodeJsonHashToBase64($_) for values %$jsonHash;
708 }
709 elsif(ref $jsonHash eq 'ARRAY'){
710 0 $_ = $self->_encodeJsonHashToBase64($_) for @$jsonHash;
711 }
712 elsif(defined $jsonHash){
713 0 return encode_base64($jsonHash, "");
714 }
715  
716 0 return $jsonHash;
717 }
718  
719 0 ▶sub _generateYaml{
Subroutine _generateYaml: not called CC=8 SCAR=42.8
720 0 my ($self) = @_;
721  
722 0 ▶ $self->_writeLog("Instance is missing.\n") and return if not defined $self->{instance};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"instance"} 0 0 0
Condition0%0/5
defined $self->{'instance'} || $self->_writeLog("Instance is missing.\n") && (return)
l!l&&r!l&&!r
000
$self->_writeLog("Instance is missing.\n") and return
!ll
00
MC/DC0%0/2
defined $self->{'instance'} || $self->_writeLog("Instance is missing.\n") && (return)
defined $self->{'instance'} $self->_writeLog("Instance is missing.\n")
Truth table0%0/3
A || B
A= defined $self->{'instance'}B= $self->_writeLog("Instance is missing.\n")
ABresult
1X1
011
000
723  
724 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (($self->{"omit"} // "") =~ /init/u or $self->{"config"}{"oct_config"}{"project"}{"omit_init"} and not +($self->{"advanceFeatures"} // "") =~ /useInit/u) 0 0 0
Condition0%0/10
($self->{"omit"} // "") =~ /init/u or $self->{"config"}{"oct_config"}{"project"}{"omit_init"} and not +($self->{"advanceFeatures"} // "") =~ /useInit/u
l!l&&r!l&&!r
000
$self->{"omit"} // ""
l!l
00
$self->{"config"}{"oct_config"}{"project"}{"omit_init"} and not +($self->{"advanceFeatures"} // "") =~ /useInit/u
!ll&&!rl&&r
000
$self->{"advanceFeatures"} // ""
l!l
00
MC/DC0%0/3
($self->{"omit"} // "") =~ /init/u or $self->{"config"}{"oct_config"}{"project"}{"omit_init"} and not +($self->{"advanceFeatures"} // "") =~ /useInit/u
$self->{"omit"} $self->{"config"}{"oct_config"}{"project"}{"omit_init"} $self->{"advanceFeatures"}
Truth table0%0/4
A or B and not(C)
A= $self->{"omit"}B= $self->{"config"}{"oct_config"}{"project"}{"omit_init"}C= $self->{"advanceFeatures"}
ABCresult
1XX1
0101
00X0
0110
725 ($self->{omit} // '') =~ /init/ ||
726 (
727 $self->{config}->{oct_config}->{project}->{omit_init} &&
728 ($self->{advanceFeatures} // '') !~ /useInit/
729 )
730 ){
731 0 $self->_removeInitFromComponentDirs();
732 }
733 0 $self->_loopDir($self->{config}->{templates_tt_dir}, "*", "_createTemplatesTTDirHash");
734 0 $self->_clearDir($self->{config}->{templates_yaml_dir});
735 0 $self->_writeYamlFiles();
736
737 0 return;
738 }
739  
740 0 ▶sub _getComponentConfigNodes{
Subroutine _getComponentConfigNodes: not called CC=4 SCAR=30.0
741 0 my ($self, $config) = @_;
742
743 0 my @componentConfigNodes;
744 my $componentConfigNodesString;
745 0 ▶ if((defined $config->{oct_config}) && (defined $config->{oct_config}->{instance_specific_data})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"oct_config"} and defined $config->{"oct_config"}{"instance_specific_data"}) 0 0 0
Condition0%0/3
defined $config->{"oct_config"} and defined $config->{"oct_config"}{"instance_specific_data"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $config->{"oct_config"} and defined $config->{"oct_config"}{"instance_specific_data"}
defined $config->{"oct_config"} defined $config->{"oct_config"}{"instance_specific_data"}
Truth table0%0/3
A and B
A= defined $config->{"oct_config"}B= defined $config->{"oct_config"}{"instance_specific_data"}
ABresult
0X0
100
111
746 0 foreach my $componentConfigNode (keys %{$config->{oct_config}->{instance_specific_data}}){
747 0 push @componentConfigNodes, $componentConfigNode;
748 }
749 }
750  
751 0 return \@componentConfigNodes;
752 }
753  
754 0 ▶sub _getComponentsFromTemplatesTTDir{
Subroutine _getComponentsFromTemplatesTTDir: not called CC=7 SCAR=37.2
755 0 my ($self) = @_;
756  
757 0 my $components = "";
758 0 foreach my $dirPath (sort {
759 # sort numerically
760 0 my ($an) = basename($a) =~ /^(\d+)/;
761 0 my ($bn) = basename($b) =~ /^(\d+)/;
762 0 ▶ ($an // 0) <=> ($bn // 0) || basename($a) cmp basename($b);
Condition0%0/7
($an // 0) <=> ($bn // 0) || basename($a) cmp basename($b)
l!l&&r!l&&!r
000
$an // 0
l!l
00
$bn // 0
l!l
00
MC/DC0%0/2
($an // 0) <=> ($bn // 0) || basename($a) cmp basename($b)
$an basename($a) cmp basename($b)
MC/DC0%0/1
$bn // 0
$bn
Truth table0%0/3
A || B
A= $anB= basename($a) cmp basename($b)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $bn
Aresult
11
00
763 1 ▶ } glob "$self->{templatesTTDir}/*"){
Subroutine BEGIN: called CC=1 SCAR=0.0
764 0 ▶ next if not -d $dirPath;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dirPath 0 0 0
765 0 my @dirPathArr = split('/', $dirPath);
766 0 my $componentDir = $dirPathArr[-1];
767 0 $componentDir =~ s/^\d+-//;
768 0 $components .= $componentDir.";";
769 }
770 0 ▶ chop($components) if $components ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $components ne "" 0 0 0
771  
772 0 return $components;
773 }
774  
775 0 ▶sub _getConfig{
Subroutine _getConfig: not called CC=33 SCAR=70.2
776 0 my ($self) = @_;
777  
778 0 my $octConfigJson = read_file($self->{octConfigFile});
779 0 my $config->{oct_config} = $self->{json}->utf8->decode($octConfigJson);
780  
781 0 ▶ $self->{config}->{oct_config}->{project}->{git} = {} if not defined $self->{config}->{oct_config}->{project}->{git};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"config"}{"oct_config"}{"project"}{"git"} 0 0 0
782
783 0 ▶ $config = $self->{addFlagValuesToConfig}->($config) if defined $self->{addFlagValuesToConfig};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"addFlagValuesToConfig"} 0 0 0
784  
785 # set/generate instance specific names
786 0 foreach my $entry (keys %{$config->{oct_config}->{instance_specific_name}}){
787 0 $config->{oct_config}->{instance_specific_name}->{$entry} .= "-$self->{instance}";
788 }
789  
790 0 $config->{allowed_clusters} = $config->{oct_config}->{project}->{allowed_clusters};
791 0 ▶ if(not defined $config->{allowed_clusters}){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $config->{'allowed_clusters'}) { } 0 0 0
792 0 print "INFO: oct_config->project->allowed_clusters json node is empty. Marking 'allowed_clusters' as '$self->{cluster}'\n";
793 0 $config->{allowed_clusters} = $self->{cluster};
794 }else{
795 0 ▶ print "Warning: Unknown cluster $self->{cluster}\n" if $config->{allowed_clusters} !~ /$self->{cluster}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $config->{"allowed_clusters"} =~ /$self->{"cluster"}/u 0 0 0
796 }
797  
798 0 $config->{cluster_ip_range} = $config->{oct_config}->{project}->{cluster_ip_range};
799 0 ▶ $config->{cluster_ip_range} = $self->{clusterIpRange} if defined $self->{clusterIpRange};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"clusterIpRange"} 0 0 0
800 0 $config->{project_name} = $config->{oct_config}->{project}->{name};
801 0 ▶ $config->{project_name} = $self->{projectName} if defined $self->{projectName};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"projectName"} 0 0 0
802 0 $config->{host} = $config->{oct_config}->{project}->{host};
803 0 ▶ $config->{host} = $self->{host} if defined $self->{host};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"host"} 0 0 0
804 0 $config->{namespace} = $config->{oct_config}->{project}->{namespace};
805 0 ▶ $config->{namespace} = $self->{namespace} if defined $self->{namespace};# from -n flag
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"namespace"} 0 0 0
806 0 ▶ $config->{namespace} = $self->_getCurrentProject() if not defined $config->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"namespace"} 0 0 0
807 # default component dirs are set here, dirs in 'templates_tt' not set as default will be omitted
808 0 $config->{component_dirs} = $config->{oct_config}->{project}->{component_dirs};
809 0 ▶ $config->{component_dirs} = $self->{components} if defined $self->{components};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"components"} 0 0 0
810 0 ▶ $config->{component_dirs} = $self->_getComponentsFromTemplatesTTDir() if not defined $config->{component_dirs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"component_dirs"} 0 0 0
811 # component dirs can contains numbers e.g.: '50-solr' so regexp match is used =>
812 # separate 'init' components in order to avoid false matches (e.g.: 20-init-api vs 50-api when 'api' searched)
813 0 my @components = split(';', $config->{component_dirs});
814 0 my $standardComponentDirs = "";
815 0 my $initComponentDirs = "";
816 0 foreach my $componentDir (@components){
817 0 ▶ if($componentDir =~ /init/){
Branch: 1 branch
BranchTrueFalseTotal
if ($componentDir =~ /init/u) { } 0 0 0
818 0 $initComponentDirs .= $componentDir.";";
819 }else{
820 0 $standardComponentDirs .= $componentDir.";";
821 }
822 }
823 0 chop($initComponentDirs);
824 0 chop($standardComponentDirs);
825 0 $config->{init_component_dirs} = $initComponentDirs;
826 0 $config->{standard_component_dirs} = $standardComponentDirs;
827 0 $config->{resource_kinds_backup} = $config->{oct_config}->{project}->{resource_kinds_backup};
828 0 ▶ $config->{resource_kinds_backup} = $self->_getDefaultKindsBackup() if not defined $config->{resource_kinds_backup};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"resource_kinds_backup"} 0 0 0
829 0 $config->{resource_kinds} = $config->{oct_config}->{project}->{resource_kinds};
830 0 ▶ $config->{resource_kinds} = $self->{resourceKinds} if defined $self->{resourceKinds};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"resourceKinds"} 0 0 0
831 0 ▶ $config->{resource_kinds} = $self->_getDefaultKinds() if not defined $config->{resource_kinds};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"resource_kinds"} 0 0 0
832 0 $config->{templates_yaml_dir} = $self->{templatesYamlDir};
833 0 $config->{templates_tt_dir} = $self->{templatesTTDir};
834 0 $config->{cluster} = $self->{cluster};
835 0 $config->{instance} = $self->{instance};
836 0 $config->{instance_capitalized_first} = ucfirst $config->{instance};
837 0 ▶ $config->{url_prefix} = $config->{oct_config}->{project}->{url_prefix} if defined $config->{oct_config}->{project}->{url_prefix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"oct_config"}{"project"}{"url_prefix"} 0 0 0
838 0 ▶ $config->{url_prefix} = $self->{urlPrefix} if defined $self->{urlPrefix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"urlPrefix"} 0 0 0
839 0 ▶ $config->{cluster_base_address} = $self->{clusterBaseAddress} if defined $self->{clusterBaseAddress};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"clusterBaseAddress"} 0 0 0
840 0 ▶ $config->{cluster_base_address} = $config->{oct_config}->{project}->{cluster_base_address} if not defined $config->{cluster_base_address};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"cluster_base_address"} 0 0 0
841
842 0 my $componentConfigNodes = $self->_getComponentConfigNodes($config);
843 0 foreach my $componentConfNode (@$componentConfigNodes){
844 # set/generate default urls
845 0 ▶ if((defined $config->{oct_config}->{instance_specific_data}->{$componentConfNode}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} and ref $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} eq "HASH") 0 0 0
Condition0%0/3
defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} and ref $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} and ref $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} eq "HASH"
defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} ref $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} eq "HASH"
Truth table0%0/3
A and B
A= defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode}B= ref $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode} eq "HASH"
ABresult
0X0
100
111
846 (ref($config->{oct_config}->{instance_specific_data}->{$componentConfNode}) eq 'HASH')){
847 0 foreach my $instanceKey (keys %{$config->{oct_config}->{instance_specific_data}->{$componentConfNode}}){
848 0 ▶ if(not defined $config->{oct_config}->{instance_specific_data}->{$componentConfNode}->{$instanceKey}->{url}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode}{$instanceKey}{"url"}) 0 0 0
849 0 my $componentNameKebab = $componentConfNode;
850 0 $componentNameKebab =~ s/_/\-/g;
851 0 my $lcInstanceKey = lc $instanceKey;
852 0 ▶ $lcInstanceKey = undef if $componentConfNode =~ /init_/; # don't add instance name to url if in 'init_' component
Branch: 1 branch
BranchTrueFalseTotal
if $componentConfNode =~ /init_/u 0 0 0
853 0 my $url = "";
854 0 ▶ if(defined $self->{generateUrl}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"generateUrl"}) 0 0 0
855 $url = $self->{generateUrl}->($config->{url_prefix},
856 $config->{project_name},
857 $componentNameKebab,
858 $lcInstanceKey,
859 $config->{cluster_base_address},
860 0 $config->{host});
861 }
862 0 $config->{oct_config}->{instance_specific_data}->{$componentConfNode}->{$instanceKey}->{url} = $url;
863 }
864 }
865 }
866 # select instance specific data
867 0 ▶ if(defined $config->{oct_config}->{instance_specific_data}->{$componentConfNode}->{$self->{instance}}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"oct_config"}{"instance_specific_data"}{$componentConfNode}{$self->{"instance"}}) 0 0 0
868 $config->{oct_config}->{instance_specific_data}->{$componentConfNode} =
869 0 $config->{oct_config}->{instance_specific_data}->{$componentConfNode}->{$self->{instance}};
870 }
871 }
872 # in worse case 36 available IP addresses(see _writeYamlFile), make number smaller if more needed(max is 256)
873 0 $config->{ip_last_number} = int(rand(220));
874
875 0 ▶ print "'Info: component_dirs' parameter is missing\n" if not defined $config->{component_dirs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"component_dirs"} 0 0 0
876 0 ▶ print "'Info: cluster_ip_range' parameter is missing\n" if not defined $config->{cluster_ip_range};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"cluster_ip_range"} 0 0 0
877 0 ▶ print "'Info: host' parameter is missing\n" if not defined $config->{host};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"host"} 0 0 0
878  
879 0 return $config;
880 }
881  
882 0 ▶sub _getCurrentProject{
Subroutine _getCurrentProject: not called CC=2 SCAR=17.9
883 0 my ($self) = @_;
884  
885 0 my $projectCmdLine = qx/$self->{cloudCommand} config current-context/;
886 0 my @projectCmdLineArr = split('/', $projectCmdLine);
887 0 my $project = $projectCmdLineArr[0];
888 0 ▶ $project = "unknown" if not defined $project;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $project 0 0 0
889  
890 0 return $project;
891 }
892  
893 0 ▶sub _getDefaultKinds{
Subroutine _getDefaultKinds: not called CC=1 SCAR=6.9
894 0 return "PersistentVolumeClaim;ImageStream;BuildConfig;Deployment;DeploymentConfig;Secret;ConfigMap;CronJob;Job;Service;Route";
895 }
896  
897 0 ▶sub _getDefaultKindsBackup{
Subroutine _getDefaultKindsBackup: not called CC=1 SCAR=6.9
898 0 return "PersistentVolumeClaim;StorageClass;VolumeSnapshot;ImageStream;BuildConfig;Deployment;DeploymentConfig;StatefulSet;Secret;ConfigMap;CronJob;Job;DaemonSet;ReplicaSet;ReplicationController;HorizontalPodAutoscaler;PodDisruptionBudget;Service;Route;Ingress;NetworkPolicy;ServiceAccount;ClusterRole;RoleBinding;ResourceQuota;LimitRange";
899 }
900  
901 0 ▶sub _getSecrets{
Subroutine _getSecrets: not called CC=15 SCAR=54.8
902 0 my ($self, $config) = @_;
903  
904 0 my $secretJsonFileName = $self->{secretsJson};
905 # secrets files for all instances and all clusters e.g.: secrets/my-secret.txt
906 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in($self->{secretsDir})) {
907 0 my @dirFileNameArr = split('/', $dirFileName);
908 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
909 0 $self->_addSecretsToConfigHash($config, $dirFileName);
910 }
911  
912 # instance specific secrets files and for all clusters e.g.: secrets/instance/test/my-secret.txt
913 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in("$self->{secretsDir}/instance/$self->{instance}")) {
914 0 my @dirFileNameArr = split('/', $dirFileName);
915 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
916 0 $self->_addSecretsToConfigHash($config, $dirFileName);
917 }
918
919 0 my $clusterSpecificSecretsDirExist = 0;
920 0 foreach my $dirPath (glob "$self->{secretsDir}/*"){
921 0 ▶ next if not -d $dirPath;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dirPath 0 0 0
922 0 my @dirPathArr = split('/', $dirPath);
923 0 my $dirName = $dirPathArr[-1];
924 0 ▶ next if $dirName eq "instance";
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq "instance" 0 0 0
925 0 ▶ $clusterSpecificSecretsDirExist = 1 if $dirName eq $self->{config}->{cluster};
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq $self->{"config"}{"cluster"} 0 0 0
926 }
927
928 # secrets files for all instances and for specific cluster e.g.: secrets/clusterIntern/my_secret.txt
929 0 ▶ if($clusterSpecificSecretsDirExist){
Branch: 1 branch
BranchTrueFalseTotal
if ($clusterSpecificSecretsDirExist) 0 0 0
930 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in("$self->{secretsDir}/$self->{config}->{cluster}")) {
931 0 my @dirFileNameArr = split('/', $dirFileName);
932 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
933 0 $self->_addSecretsToConfigHash($config, $dirFileName);
934 }
935 # secret files for specific instance and specific cluster e.g.: secrets/clusterIntern/instance/prod/my_secret.txt
936 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in("$self->{secretsDir}/$self->{config}->{cluster}/instance/$self->{instance}")) {
937 0 my @dirFileNameArr = split('/', $dirFileName);
938 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
939 0 $self->_addSecretsToConfigHash($config, $dirFileName);
940 }
941 }
942 # secrets json for all instances and all clusters
943 0 $config->{secrets_json} = {};
944 0 eval {
945 0 my $secretJson = read_file("$self->{secretsDir}/$secretJsonFileName");
946 0 my $secretJsonAllInstancesAllClustersHash = $self->{json}->utf8->decode($secretJson);
947 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonAllInstancesAllClustersHash);
948 };
949 0 ▶ if($clusterSpecificSecretsDirExist){
Branch: 1 branch
BranchTrueFalseTotal
if ($clusterSpecificSecretsDirExist) { } 0 0 0
950 # secrets json for all instances and specific cluster
951 0 my $path = "$self->{secretsDir}/$self->{config}->{cluster}/$secretJsonFileName";
952 0 eval {
953 0 my $secretJsonClusterSpecific = read_file($path);
954 0 my $secretJsonClusterSpecificHash = $self->{json}->utf8->decode($secretJsonClusterSpecific);
955 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonClusterSpecificHash);
956 };
957 # secrets json for specific instance and specific cluster
958 0 $path = "$self->{secretsDir}/$self->{config}->{cluster}/instance/$self->{instance}/$secretJsonFileName";
959 0 eval {
960 0 my $secretJsonClusterSpecificInstanceSpecific = read_file($path);
961 0 my $secretJsonClusterSpecificInstanceSpecificHash = $self->{json}->utf8->decode($secretJsonClusterSpecificInstanceSpecific);
962 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonClusterSpecificInstanceSpecificHash);
963 };
964 }else{
965 # secrets json for specific instance and all clusters
966 0 my $path = "$self->{secretsDir}/instance/$self->{instance}/$secretJsonFileName";
967 0 eval {
968 0 my $secretJsonInstanceSpecific = read_file($path);
969 0 my $secretJsonInstanceSpecificHash = $self->{json}->utf8->decode($secretJsonInstanceSpecific);
970 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonInstanceSpecificHash);
971 };
972 }
973  
974 0 return;
975 }
976  
977 0 ▶sub _getCloudWriteCommand{
Subroutine _getCloudWriteCommand: not called CC=6 SCAR=37.4
978 0 my ($self) = @_;
979  
980 0 my $writeCommand = "create";
981 0 ▶ if(defined $self->{config}->{oct_config}->{project}->{default_cloud_write_command}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"oct_config"}{"project"}{"default_cloud_write_command"}) 0 0 0
982 0 $writeCommand = $self->{config}->{oct_config}->{project}->{default_cloud_write_command};
983 }
984 0 ▶ $writeCommand = "create" if defined $self->{advanceFeatures} && $self->{advanceFeatures} =~ /create/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /create/u 0 0 0
Condition0%0/3
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /create/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /create/u
defined $self->{"advanceFeatures"} $self->{"advanceFeatures"} =~ /create/u
Truth table0%0/3
A and B
A= defined $self->{"advanceFeatures"}B= $self->{"advanceFeatures"} =~ /create/u
ABresult
0X0
100
111
985 0 ▶ $writeCommand = "apply" if defined $self->{advanceFeatures} && $self->{advanceFeatures} =~ /apply/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /apply/u 0 0 0
Condition0%0/3
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /apply/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"advanceFeatures"} and $self->{"advanceFeatures"} =~ /apply/u
defined $self->{"advanceFeatures"} $self->{"advanceFeatures"} =~ /apply/u
Truth table0%0/3
A and B
A= defined $self->{"advanceFeatures"}B= $self->{"advanceFeatures"} =~ /apply/u
ABresult
0X0
100
111
986
987 0 return $writeCommand;
988 }
989  
990 0 ▶sub _gitCommitAndPush{
Subroutine _gitCommitAndPush: not called CC=8 SCAR=42.8
991 0 my ($self, $instance) = @_;
992  
993 0 ▶ if(not $self->{config}->{oct_config}->{project}->{git}->{auto_commit}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_commit"}) 0 0 0
994 0 ▶ if($self->{config}->{oct_config}->{project}->{git}->{auto_commit_prompt}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_commit_prompt"}) 0 0 0
995 0 $self->_writeLog("\nPress enter to commit(and push if enabled) to Git or type 'skip' and press enter to skip this operation(s).\n");
996 0 my $continue = <>;
997 0 ▶ return if $continue =~ /skip/;
Branch: 1 branch
BranchTrueFalseTotal
if $continue =~ /skip/u 0 0 0
998 }
999 0 $self->_writeLog("commiting to git...\n");
1000 0 my $commitText = "committed on: " . localtime;
1001 0 ▶ if($self->{config}->{oct_config}->{project}->{git}->{auto_commit_prompt}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_commit_prompt"}) 0 0 0
1002 0 $self->_writeLog("Write your git commit message or press Enter to use default:\n($commitText)\n");
1003 0 my $customMsg = <>;
1004 0 ▶ $commitText = $customMsg if $customMsg ne "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $customMsg ne "\n" 0 0 0
1005 0 $commitText =~ s/\n//g;
1006 }
1007 0 $self->_writeLog("git commit -am \"$commitText\"\n");
1008 0 `git commit -am "$commitText"`;
1009 0 ▶ if($self->{config}->{oct_config}->{project}->{git}->{auto_push}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_push"}) 0 0 0
1010 0 ▶ my $branch = $self->{config}->{oct_config}->{project}->{git}->{auto_push_branch} // "master";
Condition0%0/2
$self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_push_branch"} // "master"
l!l
00
MC/DC0%0/1
$self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_push_branch"} // "master"
$self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_push_branch"}
Truth table0%0/2
A
A= $self->{"config"}{"oct_config"}{"project"}{"git"}{"auto_push_branch"}
Aresult
11
00
1011 0 $self->_writeLog("git push origin $branch\n");
1012 0 `git push origin $branch`;
1013 }
1014 }
1015  
1016 0 return;
1017 }
1018  
1019 0 ▶sub _initConfSecretsAndYaml{
Subroutine _initConfSecretsAndYaml: not called CC=2 SCAR=17.9
1020 0 my ($self, $instance) = @_;
1021
1022 0 $self->{instance} = $instance;
1023 0 $self->{config} = $self->_getConfig();
1024 0 $self->_runPreHook();
1025
1026 0 my $outputLogFile = "output.log";
1027 0 ▶ if(defined $self->{config}->{oct_config}->{project}->{output_log_file}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"oct_config"}{"project"}{"output_log_file"}) 0 0 0
1028 0 $outputLogFile = $self->{config}->{oct_config}->{project}->{output_log_file};
1029 }
1030 0 `touch $outputLogFile`;
1031 0 `>$outputLogFile`; # clear file content
1032  
1033 0 $self->_getSecrets($self->{config});
1034 0 $self->_generateYaml();
1035
1036 0 return;
1037 }
1038  
1039 0 ▶sub _loopDir {
Subroutine _loopDir: not called CC=20 SCAR=58.0
1040 0 my ($self, $dirToLoop, $extention, $injectedSubName, $params) = @_;
1041  
1042 0 my $templates = {};
1043 0 for my $dirFileName (File::Find::Rule->file()->name("*.$extention")->in($dirToLoop)) {
1044 0 $dirFileName =~ s/$dirToLoop\///;
1045 0 my @dirFile = split('\/', $dirFileName);
1046 0 my @dir = split('\-', $dirFile[0]);
1047 0 my @file = split('\-', $dirFile[1]);
1048 # e.g: $templates->{30-solr}->{dirNumber} = 30 # in order so sort as integer
1049 # ->{20-build-config-solr.tt} = 20
1050 0 $templates->{$dirFile[0]}->{dirNumber} = $dir[0];
1051 0 $templates->{$dirFile[0]}->{$dirFile[1]} = $file[0];
1052 }
1053  
1054 0 my @dirArray;
1055 0 ▶ if((defined $self->{sortType}) && ($self->{sortType}) eq "alphabetic"){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'sortType'} and $self->{'sortType'} eq 'alphabetic') { } 0 0 0
Condition0%0/3
defined $self->{"sortType"} and $self->{"sortType"} eq "alphabetic"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"sortType"} and $self->{"sortType"} eq "alphabetic"
defined $self->{"sortType"} $self->{"sortType"} eq "alphabetic"
Truth table0%0/3
A and B
A= defined $self->{"sortType"}B= $self->{"sortType"} eq "alphabetic"
ABresult
0X0
100
111
1056 0 foreach my $dir (sort { lc $templates->{$a}->{dirNumber} cmp lc $templates->{$b}->{dirNumber} } keys %{$templates}){
1057 0 push @dirArray, $dir;
1058 }
1059 }else{
1060 # numeric
1061 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1062 0 foreach my $dir (sort { $templates->{$a}->{dirNumber} <=> $templates->{$b}->{dirNumber} } keys %{$templates}){
1063 0 push @dirArray, $dir;
1064 }
1065 }
1066 0 ▶ @dirArray = reverse @dirArray if $injectedSubName eq "_deleteFromCloud";
Branch: 1 branch
BranchTrueFalseTotal
if $injectedSubName eq "_deleteFromCloud" 0 0 0
1067  
1068 0 foreach my $dir (@dirArray){
1069 0 ▶ $self->_writeLog("\nComponent: $dir:\n") if $injectedSubName eq "_callCloudCommand";
Branch: 1 branch
BranchTrueFalseTotal
if $injectedSubName eq "_callCloudCommand" 0 0 0
1070
1071 0 my @fileArray;
1072 0 ▶ if((defined $self->{sortType}) && ($self->{sortType}) eq "alphabetic"){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'sortType'} and $self->{'sortType'} eq 'alphabetic') { } 0 0 0
Condition0%0/3
defined $self->{"sortType"} and $self->{"sortType"} eq "alphabetic"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"sortType"} and $self->{"sortType"} eq "alphabetic"
defined $self->{"sortType"} $self->{"sortType"} eq "alphabetic"
Truth table0%0/3
A and B
A= defined $self->{"sortType"}B= $self->{"sortType"} eq "alphabetic"
ABresult
0X0
100
111
1073 0 foreach my $file (sort { lc $templates->{$dir}->{$a} cmp lc $templates->{$dir}->{$b} } keys %{$templates->{$dir}}){
1074 0 push @fileArray, $file;
1075 }
1076 }else{
1077 # numeric
1078 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1079 0 foreach my $file (sort { $templates->{$dir}->{$a} <=> $templates->{$dir}->{$b} } keys %{$templates->{$dir}}){
1080 0 push @fileArray, $file;
1081 }
1082 }
1083 0 ▶ @fileArray = reverse @fileArray if $injectedSubName eq "_deleteFromCloud";
Branch: 1 branch
BranchTrueFalseTotal
if $injectedSubName eq "_deleteFromCloud" 0 0 0
1084 0 foreach my $file (@fileArray){
1085 0 ▶ next if $file eq "dirNumber" || $self->_skipComponent($dir);
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "dirNumber" or $self->_skipComponent($dir) 0 0 0
Condition0%0/3
$file eq "dirNumber" or $self->_skipComponent($dir)
l!l&&r!l&&!r
000
MC/DC0%0/2
$file eq "dirNumber" or $self->_skipComponent($dir)
$file eq "dirNumber" $self->_skipComponent($dir)
Truth table0%0/3
A or B
A= $file eq "dirNumber"B= $self->_skipComponent($dir)
ABresult
1X1
011
000
1086 0 my @fileArr = split('\.', $file);
1087 0 ▶ if((not defined $fileArr[1]) && ($self->{config}->{allowed_clusters} !~ /$file/)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fileArr[1] or $self->{"config"}{"allowed_clusters"} =~ /$file/u) 0 0 0
Condition0%0/3
defined $fileArr[1] or $self->{"config"}{"allowed_clusters"} =~ /$file/u
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $fileArr[1] or $self->{"config"}{"allowed_clusters"} =~ /$file/u
defined $fileArr[1] $self->{"config"}{"allowed_clusters"} =~ /$file/u
Truth table0%0/3
A or B
A= defined $fileArr[1]B= $self->{"config"}{"allowed_clusters"} =~ /$file/u
ABresult
1X1
011
000
1088 0 ▶ $self->_writeLog("Warning : Unknown cluster: $file\n") if $file ne "instance";
Branch: 1 branch
BranchTrueFalseTotal
if $file ne "instance" 0 0 0
1089 }
1090 0 my $injectedSub = \&$injectedSubName;
1091 0 $injectedSub->($self, {dir => $dir, templateName => $fileArr[0], params => $params});
1092 }
1093 }
1094 }
1095  
1096 0 ▶sub _mergeSecretsJson{
Subroutine _mergeSecretsJson: not called CC=3 SCAR=24.8
1097 0 my ($self, $jsonHashOriginal, $jsonHashAddition) = @_;
1098
1099 0 ▶ if(ref($jsonHashAddition) eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $jsonHashAddition eq "HASH") 0 0 0
1100 0 foreach my $key (keys %{$jsonHashAddition}){
1101 0 $jsonHashOriginal->{$key} = $jsonHashAddition->{$key};
1102 0 $jsonHashOriginal->{base64}->{$key} = $self->_encodeJsonHashToBase64(dclone($jsonHashAddition->{$key}));
1103 }
1104 }
1105
1106 0 return;
1107 }
1108  
1109 0 ▶sub _removeInitFromComponentDirs{
Subroutine _removeInitFromComponentDirs: not called CC=1 SCAR=6.9
1110 0 my ($self) = @_;
1111
1112 0 my @componentsYamlDirArray = split(';', $self->{config}->{component_dirs});
1113 0 @componentsYamlDirArray = (grep {$_ !~ /init/} @componentsYamlDirArray);
1114 0 $self->{config}->{component_dirs} = join( ';', @componentsYamlDirArray);
1115 }
1116  
1117 0 ▶sub _runPreHook{
Subroutine _runPreHook: not called CC=4 SCAR=30.0
1118 0 my ($self) = @_;
1119
1120 0 ▶ if((($self->{omit} // '') !~ /preHook/) && (defined $self->{preHook})){
Branch: 1 branch
BranchTrueFalseTotal
if (not +($self->{"omit"} // "") =~ /preHook/u and defined $self->{"preHook"}) 0 0 0
Condition0%0/5
not +($self->{"omit"} // "") =~ /preHook/u and defined $self->{"preHook"}
!ll&&!rl&&r
000
$self->{"omit"} // ""
l!l
00
MC/DC0%0/2
not +($self->{"omit"} // "") =~ /preHook/u and defined $self->{"preHook"}
$self->{"omit"} defined $self->{"preHook"}
Truth table0%0/3
not(A) and B
A= $self->{"omit"}B= defined $self->{"preHook"}
ABresult
1X0
000
011
1121 0 $self->{preHook}->($self->{config});
1122 }
1123  
1124 0 return;
1125 }
1126  
1127 0 ▶sub _runPostHook{
Subroutine _runPostHook: not called CC=4 SCAR=30.0
1128 0 my ($self) = @_;
1129  
1130 0 ▶ if((($self->{omit} // '') !~ /postHook/) && (defined $self->{postHook})){
Branch: 1 branch
BranchTrueFalseTotal
if (not +($self->{"omit"} // "") =~ /postHook/u and defined $self->{"postHook"}) 0 0 0
Condition0%0/5
not +($self->{"omit"} // "") =~ /postHook/u and defined $self->{"postHook"}
!ll&&!rl&&r
000
$self->{"omit"} // ""
l!l
00
MC/DC0%0/2
not +($self->{"omit"} // "") =~ /postHook/u and defined $self->{"postHook"}
$self->{"omit"} defined $self->{"postHook"}
Truth table0%0/3
not(A) and B
A= $self->{"omit"}B= defined $self->{"postHook"}
ABresult
1X0
000
011
1131 0 $self->{postHook}->($self->{config});
1132 }
1133  
1134 0 return;
1135 }
1136  
1137 0 ▶sub _skipComponent{
Subroutine _skipComponent: not called CC=9 SCAR=45.0
1138 0 my ($self, $dir) = @_;
1139  
1140 # ignore skiping if called by this flag
1141 0 ▶ return 0 if defined $self->{yamlToTTconvertDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"yamlToTTconvertDir"} 0 0 0
1142
1143 0 my @installComponents = [];
1144 0 ▶ if($dir =~ /init/){
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /init/u) { } 0 0 0
1145 0 ▶ if(defined $self->{config}->{init_component_dirs}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"init_component_dirs"}) 0 0 0
1146 0 @installComponents = split(';', $self->{config}->{init_component_dirs});
1147 }
1148 0 foreach my $installComponent (@installComponents){
1149 0 ▶ return 0 if $dir =~ /$installComponent/;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ /$installComponent/u 0 0 0
1150 }
1151 }else{
1152 0 ▶ if(defined $self->{config}->{standard_component_dirs}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"standard_component_dirs"}) 0 0 0
1153 0 @installComponents = split(';', $self->{config}->{standard_component_dirs});
1154 }
1155 0 foreach my $installComponent (@installComponents){
1156 0 ▶ return 0 if $dir =~ /$installComponent/;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ /$installComponent/u 0 0 0
1157 }
1158 }
1159  
1160 0 return 1;
1161 }
1162  
1163 0 ▶sub _validateAgainstCloud{
Subroutine _validateAgainstCloud: not called CC=16 SCAR=56.1
1164 0 my ($self, $params) = @_;
1165
1166 0 my @funcName = split /::/, (caller(0))[3];
1167 0 my $dir = $params->{dir};
1168 0 my $templateName = $params->{templateName};
1169  
1170 0 my $templateNameYaml = $templateName.".yaml";
1171 0 my $yamlData = LoadFile("$self->{config}->{templates_yaml_dir}/$dir/$templateNameYaml");
1172 0 my $octName = $yamlData->{metadata}->{name};
1173 0 my $octKind = $yamlData->{kind};
1174 0 my $octJson = qx/$self->{cloudCommand} get $octKind $octName -o json/;
1175 0 my $octHash = {};
1176 0 eval {
1177 0 $octHash = $self->{json}->utf8->decode($octJson);
1178 0 ▶ if(($octKind eq "Secret") && (ref($octHash->{data}) eq 'HASH')){
Branch: 1 branch
BranchTrueFalseTotal
if ($octKind eq "Secret" and ref $octHash->{"data"} eq "HASH") 0 0 0
Condition0%0/3
$octKind eq "Secret" and ref $octHash->{"data"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$octKind eq "Secret" and ref $octHash->{"data"} eq "HASH"
$octKind eq "Secret" ref $octHash->{"data"} eq "HASH"
Truth table0%0/3
A and B
A= $octKind eq "Secret"B= ref $octHash->{"data"} eq "HASH"
ABresult
0X0
100
111
1179 0 foreach my $key (keys %{$octHash->{data}}){
1180 0 my $secret = decode_base64($octHash->{data}->{$key});
1181 0 $secret =~ s/\n//g;
1182 0 $secret =~ s/\r//g;
1183 0 $octHash->{data}->{$key} = $secret;
1184 }
1185 }
1186 };
1187 0 ▶ $self->_writeLog(Dumper($@)) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1188
1189 0 my $templateYamlText = read_file("$self->{config}->{templates_yaml_dir}/$dir/$templateNameYaml");
1190 0 my $yamlObj = YAML::Safe->new->boolean("JSON::PP");
1191 0 my $templateHash = $yamlObj->Load($templateYamlText);
1192 0 my $subParams = {"dir" => $dir, "templateName" => $templateName, "octKind" => $octKind, "octName" => $octName};
1193 0 ▶ $octHash = $self->{removeClutter}->($octHash, $subParams) if defined $self->{removeClutter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"removeClutter"} 0 0 0
1194 0 ▶ $templateHash = $self->{removeClutter}->($templateHash, $subParams) if defined $self->{removeClutter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"removeClutter"} 0 0 0
1195
1196 0 ▶ if($octKind eq "Secret"){
Branch: 1 branch
BranchTrueFalseTotal
if ($octKind eq "Secret") 0 0 0
1197 0 ▶ if((defined $templateHash->{data}) && (ref($templateHash->{data}) eq 'HASH')){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $templateHash->{"data"} and ref $templateHash->{"data"} eq "HASH") 0 0 0
Condition0%0/3
defined $templateHash->{"data"} and ref $templateHash->{"data"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $templateHash->{"data"} and ref $templateHash->{"data"} eq "HASH"
defined $templateHash->{"data"} ref $templateHash->{"data"} eq "HASH"
Truth table0%0/3
A and B
A= defined $templateHash->{"data"}B= ref $templateHash->{"data"} eq "HASH"
ABresult
0X0
100
111
1198 0 foreach my $key (keys %{$templateHash->{data}}){
1199 0 my $dataBase64Encoded = $templateHash->{data}->{$key};
1200 0 my $dataBase64Decoded = decode_base64($dataBase64Encoded);
1201 0 $dataBase64Decoded =~ s/\n//g;
1202 0 $dataBase64Decoded =~ s/\r//g;
1203 0 $templateHash->{data}->{$key} = $dataBase64Decoded;
1204 }
1205 }
1206 }
1207
1208 0 $octJson = $self->{json}->utf8->pretty->canonical->encode($octHash);
1209 0 my $templateJson = $self->{json}->utf8->pretty->canonical->encode($templateHash);
1210 0 my @octJsonArr = split /\n/, $octJson;
1211 0 my @templateJsonArr = split /\n/, $templateJson;
1212 0 my $diff = diff \@octJsonArr, \@templateJsonArr, { STYLE => "Table", CONTEXT => 0 };
1213 0 ▶ if(($octKind eq "Secret") && ($diff ne "")){
Branch: 1 branch
BranchTrueFalseTotal
if ($octKind eq "Secret" and $diff ne "") 0 0 0
Condition0%0/3
$octKind eq "Secret" and $diff ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$octKind eq "Secret" and $diff ne ""
$octKind eq "Secret" $diff ne ""
Truth table0%0/3
A and B
A= $octKind eq "Secret"B= $diff ne ""
ABresult
0X0
100
111
1214 0 $diff = "+---+-----------------------------------------------------+---+---------------------------------+
1215 * | different secret, not displayed * | different secret, not displayed |
1216 +---+-----------------------------------------------------+---+---------------------------------+
1217 ";
1218 }
1219 0 $diff =~ s/\\ No newline at end of file\s//g;
1220
1221 0 my $diffStatus;
1222 0 ▶ if((defined $diff) && ($diff ne "")){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $diff and $diff ne '') { } 0 0 0
Condition0%0/3
defined $diff and $diff ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $diff and $diff ne ""
defined $diff $diff ne ""
Truth table0%0/3
A and B
A= defined $diffB= $diff ne ""
ABresult
0X0
100
111
1223 0 $diffStatus = "MODIFIED";
1224 0 $self->{"atLeastOneModified"} = 1;
1225 }else{
1226 0 $diffStatus = "OK";
1227 }
1228 0 my $line = "$dir/$templateNameYaml;$octKind;$octName;$diffStatus\n";
1229 0 $self->_writeLog($line);
1230 0 ▶ $self->_writeLog($diff) if $diff ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $diff ne "" 0 0 0
1231 0 write_file($self->{validationReportFile}, {append => 1}, $line);
1232 }
1233  
1234 # used only during cloud write operations(install/update/delete)
1235 0 ▶sub _writeLog{
Subroutine _writeLog: not called CC=2 SCAR=17.9
1236 0 my ($self, $text) = @_;
1237  
1238 0 print $text;
1239
1240 0 my $file = "output.log";
1241 0 ▶ if(defined $self->{config}->{oct_config}->{project}->{output_log_file}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"oct_config"}{"project"}{"output_log_file"}) 0 0 0
1242 0 $file = $self->{config}->{oct_config}->{project}->{output_log_file};
1243 }
1244 0 write_file($file, {append => 1}, $text);
1245
1246 0 return;
1247 }
1248  
1249 0 ▶sub _writeYamlFile{
Subroutine _writeYamlFile: not called CC=18 SCAR=58.3
1250 0 my ($self, $params) = @_;
1251  
1252 0 my $dir = $params->{dir};
1253 0 my $templateName = $params->{templateName};
1254  
1255 # return if $dir =~ /init/ && (($self->{omit} // '') =~ /init/ || $self->{config}->{oct_config}->{project}->{omit_init});
1256
1257 0 ▶ if($dir =~ /init/ &&
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /init/u and ($self->{"omit"} // "") =~ /init/u || $self->{"config"}{"oct_config"}{"project"}{"omit_init"} && !(($self->{"advanceFeatures"} // "") =~ /useInit/u)) 0 0 0
Condition0%0/13
$dir =~ /init/u and ($self->{"omit"} // "") =~ /init/u || $self->{"config"}{"oct_config"}{"project"}{"omit_init"} && !(($self->{"advanceFeatures"} // "") =~ /useInit/u)
!ll&&!rl&&r
000
($self->{"omit"} // "") =~ /init/u or $self->{"config"}{"oct_config"}{"project"}{"omit_init"} and not +($self->{"advanceFeatures"} // "") =~ /useInit/u
l!l&&r!l&&!r
000
$self->{"omit"} // ""
l!l
00
$self->{"config"}{"oct_config"}{"project"}{"omit_init"} and not +($self->{"advanceFeatures"} // "") =~ /useInit/u
!ll&&!rl&&r
000
$self->{"advanceFeatures"} // ""
l!l
00
MC/DC0%0/4
$dir =~ /init/u and ($self->{"omit"} // "") =~ /init/u || $self->{"config"}{"oct_config"}{"project"}{"omit_init"} && !(($self->{"advanceFeatures"} // "") =~ /useInit/u)
$dir =~ /init/u $self->{"omit"} $self->{"config"}{"oct_config"}{"project"}{"omit_init"} $self->{"advanceFeatures"}
Truth table0%0/5
A and B or C and not(D)
A= $dir =~ /init/uB= $self->{"omit"}C= $self->{"config"}{"oct_config"}{"project"}{"omit_init"}D= $self->{"advanceFeatures"}
ABCDresult
0XXX0
100X0
10110
11XX1
10101
1258 (
1259 ($self->{omit} // '') =~ /init/ ||
1260 ($self->{config}->{oct_config}->{project}->{omit_init} && ($self->{advanceFeatures} // '') !~ /useInit/)
1261 )
1262 ){
1263 0 return;
1264 }
1265
1266 0 ▶ return if (defined $self->{specificYamlFile}) && ($templateName !~ /$self->{specificYamlFile}/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"specificYamlFile"} and not $templateName =~ /$self->{"specificYamlFile"}/u 0 0 0
Condition0%0/3
defined $self->{"specificYamlFile"} and not $templateName =~ /$self->{"specificYamlFile"}/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"specificYamlFile"} and not $templateName =~ /$self->{"specificYamlFile"}/u
defined $self->{"specificYamlFile"} not $templateName =~ /$self->{"specificYamlFile"}/u
Truth table0%0/3
A and not(B)
A= defined $self->{"specificYamlFile"}B= not $templateName =~ /$self->{"specificYamlFile"}/u
ABresult
0X0
100
111
1267 return if (defined $self->{componentIsAllowed}) &&
1268 0 ▶ (not $self->{componentIsAllowed}->($templateName, $dir, $self->{config}->{cluster}, $self->{instance}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"componentIsAllowed"} and not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"}) 0 0 0
Condition0%0/3
defined $self->{"componentIsAllowed"} and not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"componentIsAllowed"} and not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
defined $self->{"componentIsAllowed"} not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
Truth table0%0/3
A and not(B)
A= defined $self->{"componentIsAllowed"}B= not $self->{"componentIsAllowed"}->($templateName, $dir, $self->{"config"}{"cluster"}, $self->{"instance"})
ABresult
0X0
100
111
1269
1270 0 my $yamlText;
1271 0 my $templatesYamlFilePath = "$self->{config}->{templates_yaml_dir}/$dir";
1272 0 ▶ make_path $templatesYamlFilePath or die("Failed to create path: $templatesYamlFilePath") if !-d $templatesYamlFilePath;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $templatesYamlFilePath 0 0 0
Condition0%0/5
-d $templatesYamlFilePath || (make_path($templatesYamlFilePath) || die("Failed to create path: $templatesYamlFilePath"))
l!l&&r!l&&!r
000
make_path($templatesYamlFilePath) or die "Failed to create path: $templatesYamlFilePath"
l!l
00
MC/DC0%0/2
-d $templatesYamlFilePath || (make_path($templatesYamlFilePath) || die("Failed to create path: $templatesYamlFilePath"))
-d $templatesYamlFilePath make_path($templatesYamlFilePath)
Truth table0%0/3
A || B
A= -d $templatesYamlFilePathB= make_path($templatesYamlFilePath)
ABresult
1X1
011
000
1273  
1274 # $self->{templatesTTHash}->{"40-api"}->{"40-build-config-api"} = "40-api/clusterPublic/40-build-config-api";
1275 0 my $templateTTFilePath = "$self->{templatesTTDir}/$self->{templatesTTHash}->{$dir}->{$templateName}";
1276 0 $templateTTFilePath = $templateTTFilePath.".tt";
1277  
1278 0 eval { $self->{tt}->process($templateTTFilePath, $self->{config}, \$yamlText); };
1279 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1280 0 $self->_writeLog("Error occurred during generating yaml in: $dir $templateName\n".Dumper($@)."\n");
1281 0 return;
1282 }
1283  
1284 0 my $yamlHash;
1285 0 eval { $yamlHash = Load($yamlText);};
1286 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1287 0 $self->_writeLog("Error occurred during conversion to yaml in: $dir $templateName\n".Dumper($@)."\n");
1288 0 return;
1289 }
1290  
1291 0 $self->{templateManifests}->{$yamlHash->{kind}}->{$yamlHash->{metadata}->{name}} = 1;
1292
1293 0 my $allowedResourceKinds = $self->{config}->{resource_kinds};
1294 0 ▶ return if (defined $allowedResourceKinds) && ($allowedResourceKinds !~ /$yamlHash->{kind}/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $allowedResourceKinds and not $allowedResourceKinds =~ /$yamlHash->{"kind"}/u 0 0 0
Condition0%0/3
defined $allowedResourceKinds and not $allowedResourceKinds =~ /$yamlHash->{"kind"}/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $allowedResourceKinds and not $allowedResourceKinds =~ /$yamlHash->{"kind"}/u
defined $allowedResourceKinds not $allowedResourceKinds =~ /$yamlHash->{"kind"}/u
Truth table0%0/3
A and not(B)
A= defined $allowedResourceKindsB= not $allowedResourceKinds =~ /$yamlHash->{"kind"}/u
ABresult
0X0
100
111
1295  
1296 0 write_file("$templatesYamlFilePath/$templateName\.yaml", $yamlText);
1297 0 ▶ $self->{config}->{ip_last_number}++ if $yamlHash->{kind} eq "Service";
Branch: 1 branch
BranchTrueFalseTotal
if $yamlHash->{"kind"} eq "Service" 0 0 0
1298 }
1299  
1300 0 ▶sub _writeYamlFiles{
Subroutine _writeYamlFiles: not called CC=7 SCAR=37.3
1301 0 my ($self) = @_;
1302  
1303 # $self->{templatesTTHash}->{"40-api"}->{"40-build-config-api"} = "40-api/clusterPublic/40-build-config-api.tt";
1304 0 my $dirs = $self->{templatesTTHash};
1305 0 ▶ if((defined $self->{sortType}) && ($self->{sortType}) eq "alphabetic"){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'sortType'} and $self->{'sortType'} eq 'alphabetic') { } 0 0 0
Condition0%0/3
defined $self->{"sortType"} and $self->{"sortType"} eq "alphabetic"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"sortType"} and $self->{"sortType"} eq "alphabetic"
defined $self->{"sortType"} $self->{"sortType"} eq "alphabetic"
Truth table0%0/3
A and B
A= defined $self->{"sortType"}B= $self->{"sortType"} eq "alphabetic"
ABresult
0X0
100
111
1306 # alphabetic
1307 0 foreach my $dir (sort {lc($a) cmp lc($b)} keys %{$dirs}){
1308 0 my $files = $dirs->{$dir};
1309 0 foreach my $templateName (sort {lc($a) cmp lc($b)} keys %{$files}){
1310 0 $self->_writeYamlFile({dir => $dir, templateName => $templateName});
1311 }
1312 }
1313 }else{
1314 # numeric
1315 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1316 0 foreach my $dir (sort {lc($a) <=> lc($b)} keys %{$dirs}){
1317 0 my $files = $dirs->{$dir};
1318 0 foreach my $templateName (sort {lc($a) <=> lc($b)} keys %{$files}){
1319 0 $self->_writeYamlFile({dir => $dir, templateName => $templateName});
1320 }
1321 }
1322 }
1323  
1324 0 return;
1325 }
1326  
1327 1 1;
1328  
1329 __END__
↑ Summary