blib/lib/OcToolkit.pm

filter: Statementstmt 6.9% 61 / 873 Branchbran 0.0% 0 / 360 Conditioncond 0.0% 0 / 169 MC/DCmcdc 0.0% 0 / 89 Subroutinesub 30.7% 20 / 65 Podpod 38.4% 5 / 13 totaltotal 5.4% 86 / 1569 CC 293 SCAR 57.7
CC
293
Cov
4%
_getConfig
1122.0
setParams
812.0
_deleteUndefinedResourcesInCloud
756.0
CRAP 321.1
↑ 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.19";
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=28 SCAR=67.0
Pod undocumented
292 0 my ($self, $params) = @_;
293  
294 0 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) 0 0 0
295 0 ▶ $self->{advanceFeatures} = $params->{advanceFeatures} if defined $params->{advanceFeatures};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"advanceFeatures"} 0 0 0
296 0 ▶ $self->{clusterBaseAddress} = $params->{clusterBaseAddress} if defined $params->{clusterBaseAddress};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"clusterBaseAddress"} 0 0 0
297 0 ▶ $self->{cluster} = $params->{cluster} if defined $params->{cluster};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"cluster"} 0 0 0
298 0 ▶ $self->{octConfigFile} = $params->{octConfigFile} if defined $params->{octConfigFile};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"octConfigFile"} 0 0 0
299 0 ▶ $self->{gitRevertHash} = $params->{gitRevertHash} if defined $params->{gitRevertHash};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"gitRevertHash"} 0 0 0
300 0 ▶ $self->{host} = $params->{host} if defined $params->{host};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"host"} 0 0 0
301 0 ▶ $self->{resourceKinds} = $params->{resourceKinds} if defined $params->{resourceKinds};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"resourceKinds"} 0 0 0
302 0 ▶ $self->{components} = $params->{components} if defined $params->{components};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"components"} 0 0 0
303 0 ▶ $self->{namespace} = $params->{namespace} if defined $params->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"namespace"} 0 0 0
304 0 ▶ $self->{projectName} = $params->{projectName} if defined $params->{projectName};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"projectName"} 0 0 0
305 0 ▶ $self->{omit} = $params->{omit} if defined $params->{omit};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"omit"} 0 0 0
306 0 ▶ $self->{urlPrefix} = $params->{urlPrefix} if defined $params->{urlPrefix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"urlPrefix"} 0 0 0
307 0 ▶ $self->{clusterIpRange} = $params->{clusterIpRange} if defined $params->{clusterIpRange};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"clusterIpRange"} 0 0 0
308 0 ▶ $self->{secretsDir} = $params->{secretsDir} if defined $params->{secretsDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"secretsDir"} 0 0 0
309 0 ▶ $self->{sortType} = $params->{sortType} if defined $params->{sortType};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"sortType"} 0 0 0
310 0 ▶ $self->{templatesTTDir} = $params->{templatesTTDir} if defined $params->{templatesTTDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"templatesTTDir"} 0 0 0
311 0 ▶ $self->{yamlToTTconvertDir} = $params->{yamlToTTconvertDir} if defined $params->{yamlToTTconvertDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"yamlToTTconvertDir"} 0 0 0
312 0 ▶ $self->{specificYamlFile} = $params->{specificYamlFile} if defined $params->{specificYamlFile};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"specificYamlFile"} 0 0 0
313 0 ▶ $self->{templatesYamlDir} = $params->{templatesYamlDir} if defined $params->{templatesYamlDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"templatesYamlDir"} 0 0 0
314 0 ▶ $self->{validationReportFile} = $params->{validationReportFile} if defined $params->{validationReportFile};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"validationReportFile"} 0 0 0
315 0 ▶ $self->{projectDir} = $params->{projectDir} if defined $params->{projectDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"projectDir"} 0 0 0
316 0 ▶ $self->{addFlagValuesToConfig} = $params->{addFlagValuesToConfig} if defined $params->{addFlagValuesToConfig};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"addFlagValuesToConfig"} 0 0 0
317 0 ▶ $self->{componentIsAllowed} = $params->{componentIsAllowed} if defined $params->{componentIsAllowed};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"componentIsAllowed"} 0 0 0
318 0 ▶ $self->{generateUrl} = $params->{generateUrl} if defined $params->{generateUrl};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"generateUrl"} 0 0 0
319 0 ▶ $self->{removeClutter} = $params->{removeClutter} if defined $params->{removeClutter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"removeClutter"} 0 0 0
320 0 ▶ $self->{removeClutterBackup} = $params->{removeClutterBackup} if defined $params->{removeClutterBackup};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"removeClutterBackup"} 0 0 0
321 }
322 0 return;
323 }
324  
325 0 ▶sub scaleToZero{
Subroutine scaleToZero: not called CC=4 SCAR=30.0
Pod undocumented
326 0 my ($self, $instance) = @_;
327  
328 0 $self->_initConfSecretsAndYaml($instance);
329  
330 0 foreach my $resourceName (keys %{$self->{templateManifests}->{Deployment}}){
331 0 print "$self->{cloudCommand} scale Deployment $resourceName --replicas=0\n";
332 0 qx/$self->{cloudCommand} scale Deployment $resourceName --replicas=0/;
333 }
334 0 foreach my $resourceName (keys %{$self->{templateManifests}->{DeploymentConfig}}){
335 0 print "$self->{cloudCommand} scale DeploymentConfig $resourceName --replicas=0\n";
336 0 qx/$self->{cloudCommand} scale DeploymentConfig $resourceName --replicas=0/;
337 }
338 0 foreach my $resourceName (keys %{$self->{templateManifests}->{StatefulSet}}){
339 0 print "$self->{cloudCommand} scale StatefulSet $resourceName --replicas=0\n";
340 0 qx/$self->{cloudCommand} scale StatefulSet $resourceName --replicas=0/;
341 }
342  
343 0 return;
344 }
345  
346 0 ▶sub update{
Subroutine update: not called CC=12 SCAR=50.5
Pod documented
347 0 my ($self, $instance, $skipPostHooks, $skipGitCommit) = @_;
348
349 0 $self->validateAgainstCloud($instance, $skipPostHooks);
350  
351 0 ▶ if(not $self->{atLeastOneModified}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"atLeastOneModified"}) 0 0 0
352 0 print "No updated needed.\n";
353 0 return;
354 }
355
356 0 my $cluster = $self->{config}->{cluster};
357 0 my $namespace = $self->{config}->{namespace};
358 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
359 0 ▶ return if not $self->_confirmOperation("Update", $instance, $cluster, $namespace);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_confirmOperation("Update", $instance, $cluster, $namespace) 0 0 0
360
361 0 my $validationReport = read_file($self->{validationReportFile});
362 0 my @validationReportLines = split /\n/, $validationReport;
363 0 my $atLeastOneUpdated = 0;
364 0 foreach my $line (@validationReportLines){
365 0 my @items = split /;/, $line;
366 0 ▶ if($items[-1] eq "MODIFIED"){
Branch: 1 branch
BranchTrueFalseTotal
if ($items[-1] eq "MODIFIED") 0 0 0
367 0 $atLeastOneUpdated = 1;
368 0 my $pathAndFile = $items[0];
369 0 my $octKind = $items[1];
370 0 my $octName = $items[2];
371 0 ▶ if($octKind eq "PersistentVolumeClaim"){
Branch: 1 branch
BranchTrueFalseTotal
if ($octKind eq "PersistentVolumeClaim") 0 0 0
372 0 my $text = "You are trying to update PersistentVolumeClaim.
373 Please make sure that all PODs that use this Persisten Volume are turned down before update.
374 If update operation start hanging at this step press ctrl+c to abort. \n\n";
375 0 $self->_writeLog($text);
376 }
377 0 $self->_writeLog("Updating octKind:$octKind, octName: $octName from $pathAndFile\n");
378 0 my $writeCommand = $self->_getCloudWriteCommand();
379 0 my $outputText = "";
380 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
381 0 $self->_writeLog($outputText);
382 0 my $templatesYamlDir = $self->{config}->{templates_yaml_dir};
383 0 $outputText = qx/$self->{cloudCommand} $writeCommand -f $templatesYamlDir\/$pathAndFile 2>&1/;
384 0 $self->_writeLog($outputText);
385 }
386 }
387 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
388 0 ▶ $self->_runPostHook() if not defined $skipPostHooks;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skipPostHooks 0 0 0
389
390 0 return $atLeastOneUpdated;
391 }
392  
393 0 ▶sub validateAgainstCloud{
Subroutine validateAgainstCloud: not called CC=2 SCAR=17.9
Pod undocumented
394 0 my ($self, $instance, $skipPostHooks) = @_;
395  
396 0 qx/> $self->{validationReportFile}/; # clear file
397
398 0 $self->_initConfSecretsAndYaml($instance);
399
400 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "yaml", "_validateAgainstCloud");
401 0 ▶ $self->_runPostHook() if not defined $skipPostHooks;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skipPostHooks 0 0 0
402
403 0 return;
404 }
405  
406 0 ▶sub validateManifests{
Subroutine validateManifests: not called CC=2 SCAR=17.9
Pod undocumented
407 0 my ($self, $instance, $skipPostHooks) = @_;
408
409 0 $self->_initConfSecretsAndYaml($instance);
410 0 $self->_loopDir($self->{config}->{templates_yaml_dir}, "yaml", "_callCloudCommand", {_callCloudCommand => {dryRun => 1}});
411 0 ▶ $self->_runPostHook() if not defined $skipPostHooks;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $skipPostHooks 0 0 0
412
413 0 return;
414 }
415  
416 0 ▶sub _addSecretsToConfigHash{
Subroutine _addSecretsToConfigHash: not called CC=1 SCAR=6.9
417 0 my ($self, $config, $dirFileName) = @_;
418  
419 0 my @dirFileNameArr = split('/', $dirFileName); # test, prod etc.
420 0 my $secretText = read_file($dirFileName);
421 0 $config->{secrets}->{$dirFileNameArr[-1]} = $secretText;
422
423 0 my $secretTextBase64 = encode_base64($secretText, "");
424 0 $config->{secrets}->{base64}->{$dirFileNameArr[-1]} = $secretTextBase64;
425  
426 0 return;
427 }
428  
429 0 ▶sub _backupInstance{
Subroutine _backupInstance: not called CC=4 SCAR=30.0
430 0 my ($self, $params) = @_;
431  
432 0 my $dir = $params->{dir};
433 0 my $templateName = $params->{templateName};
434  
435 0 my $instance = $self->{config}->{instance};
436 0 $self->_createDir("backups\/$instance\/$dir");
437 0 my $pathToYamlFile = "$self->{config}->{templates_yaml_dir}/$dir/$templateName".".yaml";
438 0 my $templateData = LoadFile($pathToYamlFile);
439
440 0 my $yamlText;
441 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
442 ($self->{advanceFeatures} =~ /removeClutter/) &&
443 (defined $self->{removeClutterBackup})){
444 0 print "$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o json\n";
445 0 my $octJson = qx/$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o json/;
446 0 my $octHash = $self->{json}->utf8->decode($octJson);
447 0 my $subParams = {"octKind" => $templateData->{kind}, "octName" => $templateData->{metadata}->{name}};
448 0 $octHash = $self->{removeClutterBackup}->($octHash, $subParams);
449 0 my $yamlSaveObj = YAML::Safe->new->boolean("JSON::PP");
450 0 $yamlText = $yamlSaveObj->Dump($octHash);
451 0 $yamlText =~ s/---\n//;
452 }else{
453 0 print "$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o yaml\n";
454 0 $yamlText = qx/$self->{cloudCommand} get $templateData->{kind} $templateData->{metadata}->{name} -o yaml/;
455 }
456  
457 0 write_file("$self->{projectDir}backups\/$instance\/$dir/$templateName".".yaml", $yamlText);
458 }
459  
460 0 ▶sub _callCloudCommand{
Subroutine _callCloudCommand: not called CC=7 SCAR=40.3
461 0 my ($self, $params) = @_;
462
463 0 my @funcName = split /::/, (caller(0))[3];
464 0 my $dir = $params->{dir};
465 0 my $templateName = $params->{templateName};
466 0 my $customParams = $params->{params}->{$funcName[-1]};
467  
468 return if (defined $self->{componentIsAllowed}) &&
469 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
470  
471 0 my $templateNameYaml = $templateName.".yaml";
472 0 my $pathAndFile = $self->{config}->{templates_yaml_dir}."\/$dir\/$templateNameYaml";
473 0 my $yamlData = LoadFile($pathAndFile);
474  
475 0 ▶ if(not defined $customParams->{dryRun}){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $customParams->{'dryRun'}) { } 0 0 0
476 0 my $writeCommand = $self->_getCloudWriteCommand();
477 0 $self->_writeLog("$self->{cloudCommand} $writeCommand -f $pathAndFile\n");
478 0 my $outputText = qx/$self->{cloudCommand} $writeCommand -f $pathAndFile 2>&1/;
479 0 $self->_writeLog($outputText);
480 }else{
481 0 my $infoText = "$dir\/$templateNameYaml";
482 0 my $text = qx/$self->{cloudCommand} apply --dry-run=server --validate=true -f $pathAndFile 2>&1/;
483 0 my $isError = $? >> 8;
484 0 ▶ if($isError){
Branch: 1 branch
BranchTrueFalseTotal
if ($isError) { } 0 0 0
485 0 ▶ $text = $self->{ignoreManifestValidationErrors}->($text) if defined $self->{ignoreManifestValidationErrors};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ignoreManifestValidationErrors"} 0 0 0
486 0 ▶ if($text ne ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($text ne '') { } 0 0 0
487 0 print "$infoText ERROR\n";
488 0 print "============\n$text\n============\n";
489 }else{
490 # ignore this error
491 0 print "$infoText OK\n";
492 }
493 }else{
494 0 print "$infoText;OK\n";
495 }
496 }
497
498 0 return;
499 }
500  
501 0 ▶sub _clearDir{
Subroutine _clearDir: not called CC=1 SCAR=6.9
502 0 my ($self, $dir) = @_;
503  
504 0 rmtree $dir;
505 0 make_path $dir;
506 }
507  
508 0 ▶sub _confirmOperation{
Subroutine _confirmOperation: not called CC=12 SCAR=50.5
509 0 my ($self, $type, $instance, $cluster, $namespace) = @_;
510
511 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
512
513 0 $self->_writeLog(qx/oc project/);
514
515 0 my $components;
516 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
517 0 $components = $self->{config}->{standard_component_dirs};
518 }else{
519 0 $components = $self->{config}->{component_dirs};
520 }
521 0 ▶ $components = "all" if not defined $components;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $components 0 0 0
522 0 my $preposition = "for";
523 0 ▶ $preposition = "from" if $type eq "Delete";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "Delete" 0 0 0
524 0 my $componentsText = "\nCOMPONENT(S): '$components' $preposition";
525
526 0 my $confirmOperationText = "";
527 0 ▶ if(defined $self->{specificYamlFile}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"specificYamlFile"}) 0 0 0
528 0 $confirmOperationText = "\nFILE NAME CONTAINS:'$self->{specificYamlFile}' in";
529 }
530
531 0 ▶ if(defined $self->{resourceKinds}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"resourceKinds"}) 0 0 0
532 0 $confirmOperationText .= "\nKIND(s): '$self->{resourceKinds}' in";
533 }
534
535 0 my $continue = "";
536 0 my $infoText = "\n$type $confirmOperationText $componentsText\nINSTANCE: '$instance' in\nNAMESPACE: '$namespace' in\nCLUSTER: '$cluster'\n";
537 0 $self->_writeLog($infoText);
538 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
539 0 $self->_writeLog("Press enter to continue or type: 'skip' and press enter to skip this operation.\n");
540 0 $continue = <>;
541 }
542
543 0 return $continue !~ /skip/;
544 }
545  
546 0 ▶sub _convertYamlToTTExtention{
Subroutine _convertYamlToTTExtention: not called CC=1 SCAR=6.9
547 0 my ($self, $params) = @_;
548  
549 0 my @funcName = split /::/, (caller(0))[3];
550 0 my $dir = $params->{dir};
551 0 my $templateName = $params->{templateName};
552 0 my $customParams = $params->{params}->{$funcName[-1]};
553 0 my $yamlToTTconvertDir = $customParams->{yamlToTTconvertDir};
554
555 0 my $path = "$yamlToTTconvertDir/$dir";
556 0 qx/mv $path\/$templateName\.yaml $path\/$templateName\.tt 2>&1/;
557 }
558  
559 0 ▶sub _createTemplatesTTDirHash{
Subroutine _createTemplatesTTDirHash: not called CC=9 SCAR=45.0
560 0 my ($self, $params) = @_;
561
562 0 my $dir = $params->{dir};
563 0 my $templateName = $params->{templateName};
564  
565 # $self->{templatesTTHash}->{"40-api"}->{"40-build-config-api"} = "40-api/clusterIntern/40-build-config-api";
566 # $self->{templatesTTHash}->{"40-api"}->{"45-build-config-api"} = "40-api/test/40-build-config-api";
567 # $self->{templatesTTHash}->{"40-api"}->{"46-build-config-api"} = "40-api/clusterPublic/instance/prod/40-build-config-api";
568 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
569 0 $self->{templatesTTHash}->{$dir}->{$templateName} = "$dir/$templateName";
570 }elsif($templateName eq $self->{config}->{cluster}){
571 0 for my $dirFileName (File::Find::Rule
572 ->file()
573 ->name("*")
574 ->maxdepth(1)
575 ->in("$self->{templatesTTDir}/$dir/$self->{config}->{cluster}")){
576 0 my @dirFileNameArr = split('/', $dirFileName);
577 0 my $templName = substr($dirFileNameArr[-1], 0, -3);
578 0 $self->{templatesTTHash}->{$dir}->{$templName} = "$dir/$self->{config}->{cluster}/$templName";
579 }
580 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
581 0 for my $dirFileName (File::Find::Rule
582 ->file()
583 ->name("*")
584 ->maxdepth(1)
585 ->in("$self->{templatesTTDir}/$dir/$self->{config}->{cluster}/instance/$self->{config}->{instance}")){
586 0 my @dirFileNameArr = split('/', $dirFileName);
587 0 my $templName = substr($dirFileNameArr[-1], 0, -3);
588 0 $self->{templatesTTHash}->{$dir}->{$templName} =
589 "$dir/$self->{config}->{cluster}/instance/$self->{config}->{instance}/$templName";
590 }
591 }
592 ▶ }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
593 0 for my $dirFileName (File::Find::Rule
594 ->file()
595 ->name("*")
596 ->maxdepth(1)
597 ->in("$self->{templatesTTDir}/$dir/instance/$self->{config}->{instance}")){
598 0 my @dirFileNameArr = split('/', $dirFileName);
599 0 my $templName = substr($dirFileNameArr[-1], 0, -3);
600 0 $self->{templatesTTHash}->{$dir}->{$templName} = "$dir/instance/$self->{config}->{instance}/$templName";
601 }
602 }
603  
604 0 return;
605 }
606  
607 0 ▶sub _createDir{
Subroutine _createDir: not called CC=1 SCAR=6.9
608 0 my ($self, $relativeDirPath) = @_;
609 0 qx/mkdir $self->{projectDir}$relativeDirPath 2>&1/;
610 0 return;
611 }
612  
613 0 ▶sub _deleteFromCloud{
Subroutine _deleteFromCloud: not called CC=1 SCAR=6.9
614 0 my ($self, $params) = @_;
615  
616 0 my $dir = $params->{dir};
617 0 my $templateName = $params->{templateName};
618  
619 0 my $data = LoadFile("$self->{config}->{templates_yaml_dir}/$dir/$templateName".".yaml");
620 0 $self->_writeLog("$self->{cloudCommand} delete $data->{kind} $data->{metadata}->{name}\n");
621 0 my $outputText = qx/$self->{cloudCommand} delete $data->{kind} $data->{metadata}->{name} 2>&1/;
622 0 $self->_writeLog($outputText);
623
624 0 return;
625 }
626  
627 0 ▶sub _deleteUndefinedResourcesInCloud{
Subroutine _deleteUndefinedResourcesInCloud: not called CC=27 SCAR=66.3
628 0 my ($self, $instance) = @_;
629
630 # get $self->{templateManifests} for all instances in current cluster
631 0 my $allClusterInstances;
632 0 my $cluster = $self->{config}->{cluster};
633 0 my $confingProject = $self->{config}->{oct_config}->{project};
634 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
635 defined $confingProject->{git}->{revert_multiple_instances_in_same_project} &&
636 defined $confingProject->{git}->{revert_multiple_instances_in_same_project}->{$cluster}
637 ){
638 0 $allClusterInstances = dclone($confingProject->{git}->{revert_multiple_instances_in_same_project}->{$cluster});
639 # remove current instance, it is already processed
640 0 @$allClusterInstances = grep { $_ ne $instance } @$allClusterInstances;
641
642 0 foreach my $cInstance (@$allClusterInstances){
643 0 $self->{instance} = $cInstance;
644 0 $self->{config} = $self->_getConfig();
645 0 $self->_generateYaml();
646 }
647 # bring back current instace to 'template_yaml'
648 0 $self->{instance} = $instance;
649 0 $self->{config} = $self->_getConfig();
650 0 $self->_generateYaml();
651 }
652
653 0 my $resourceKinds = $self->{config}->{resource_kinds};
654 0 my @resourceKindsArr = split(';', $resourceKinds);
655
656 # get resources from Cloud
657 0 my $cloudVsManifestDiff;
658 0 foreach my $resourceKind (@resourceKindsArr){
659 0 my $text = qx/$self->{cloudCommand} get $resourceKind/;
660 0 my @textArr = split("\n", $text);
661 0 shift @textArr;
662 0 foreach my $textLine (@textArr){
663 0 my ($resourceName) = split /\s+/, $textLine =~ s/^\s+//r; # remove also leading spaces
664 0 $cloudVsManifestDiff->{$resourceKind}->{$resourceName} = 1;
665 }
666 }
667  
668 0 my @revertExemptionsArr = ();
669 0 my $revertExemptions = $self->{config}->{oct_config}->{project}->{revert_exemptions};
670 0 ▶ @revertExemptionsArr = split(';', $revertExemptions) if defined $revertExemptions;
Branch: 1 branch
BranchTrueFalseTotal
if defined $revertExemptions 0 0 0
671
672 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
673 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
674 0 foreach my $revertExemption (@revertExemptionsArr){
675 0 ▶ if($resourceName =~ /$revertExemption/){
Branch: 1 branch
BranchTrueFalseTotal
if ($resourceName =~ /$revertExemption/u) 0 0 0
676 # don't delete this resource, remove him from template manifests vs cloud resources difference hash
677 0 delete $cloudVsManifestDiff->{$resourceKind}->{$resourceName};
678 }
679 }
680 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
681 0 delete $cloudVsManifestDiff->{$resourceKind}->{$resourceName};
682 }
683 }
684 }
685  
686 0 my $cloudVsManifestDiffIsEmpty = 1;
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 $cloudVsManifestDiffIsEmpty = 0;
691 }
692 }
693 }
694
695 0 my $atLeastOneDeleted = 0;
696 0 ▶ if(not $cloudVsManifestDiffIsEmpty){
Branch: 1 branch
BranchTrueFalseTotal
unless ($cloudVsManifestDiffIsEmpty) 0 0 0
697 0 $self->_writeLog("\nThis resources are not defined in Manifests but they are found in Cloud:\n");
698 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
699 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
700 0 $self->_writeLog(sprintf "Resource kind: %-25s Resource name: %s\n", $resourceKind, $resourceName);
701 }
702 }
703 0 my $continue = "";
704 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
705 0 $self->_writeLog("\nPress enter to delete them or type 'skip' and press enter to keep them:\n");
706 0 $continue = <>;
707 }
708 0 ▶ if($continue !~ /skip/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($continue =~ /skip/u) 0 0 0
709 0 foreach my $resourceKind (keys %{$cloudVsManifestDiff}){
710 0 foreach my $resourceName (keys %{$cloudVsManifestDiff->{$resourceKind}}){
711 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
712 0 $atLeastOneDeleted = 1;
713 0 $self->_writeLog("$self->{cloudCommand} delete $resourceKind $resourceName\n");
714 0 my $outputText = qx/$self->{cloudCommand} delete $resourceKind $resourceName 2>&1/;
715 0 $self->_writeLog($outputText);
716 }
717 }
718 }
719 }
720 }
721  
722 0 return $atLeastOneDeleted;
723 }
724  
725 0 ▶sub _encodeJsonHashToBase64{
Subroutine _encodeJsonHashToBase64: not called CC=6 SCAR=37.4
726 0 my ($self, $jsonHash) = @_;
727  
728 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
729 0 $_ = $self->_encodeJsonHashToBase64($_) for values %$jsonHash;
730 }
731 elsif(ref $jsonHash eq 'ARRAY'){
732 0 $_ = $self->_encodeJsonHashToBase64($_) for @$jsonHash;
733 }
734 elsif(defined $jsonHash){
735 0 return encode_base64($jsonHash, "");
736 }
737  
738 0 return $jsonHash;
739 }
740  
741 0 ▶sub _generateYaml{
Subroutine _generateYaml: not called CC=8 SCAR=42.8
742 0 my ($self) = @_;
743  
744 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
745  
746 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
747 ($self->{omit} // '') =~ /init/ ||
748 (
749 $self->{config}->{oct_config}->{project}->{omit_init} &&
750 ($self->{advanceFeatures} // '') !~ /useInit/
751 )
752 ){
753 0 $self->_removeInitFromComponentDirs();
754 }
755 0 $self->_loopDir($self->{config}->{templates_tt_dir}, "*", "_createTemplatesTTDirHash");
756 0 $self->_clearDir($self->{config}->{templates_yaml_dir});
757 0 $self->_writeYamlFiles();
758
759 0 return;
760 }
761  
762 0 ▶sub _getComponentConfigNodes{
Subroutine _getComponentConfigNodes: not called CC=4 SCAR=30.0
763 0 my ($self, $config) = @_;
764
765 0 my @componentConfigNodes;
766 my $componentConfigNodesString;
767 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
768 0 foreach my $componentConfigNode (keys %{$config->{oct_config}->{instance_specific_data}}){
769 0 push @componentConfigNodes, $componentConfigNode;
770 }
771 }
772  
773 0 return \@componentConfigNodes;
774 }
775  
776 0 ▶sub _getComponentsFromTemplatesTTDir{
Subroutine _getComponentsFromTemplatesTTDir: not called CC=7 SCAR=37.2
777 0 my ($self) = @_;
778  
779 0 my $components = "";
780 0 foreach my $dirPath (sort {
781 # sort numerically
782 0 my ($an) = basename($a) =~ /^(\d+)/;
783 0 my ($bn) = basename($b) =~ /^(\d+)/;
784 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
785 1 ▶ } glob "$self->{templatesTTDir}/*"){
Subroutine BEGIN: called CC=1 SCAR=0.0
786 0 ▶ next if not -d $dirPath;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dirPath 0 0 0
787 0 my @dirPathArr = split('/', $dirPath);
788 0 my $componentDir = $dirPathArr[-1];
789 0 $componentDir =~ s/^\d+-//;
790 0 $components .= $componentDir.";";
791 }
792 0 ▶ chop($components) if $components ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $components ne "" 0 0 0
793  
794 0 return $components;
795 }
796  
797 0 ▶sub _getConfig{
Subroutine _getConfig: not called CC=33 SCAR=70.2
798 0 my ($self) = @_;
799  
800 0 my $octConfigJson = read_file($self->{octConfigFile});
801 0 my $config->{oct_config} = $self->{json}->utf8->decode($octConfigJson);
802  
803 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
804
805 0 ▶ $config = $self->{addFlagValuesToConfig}->($config) if defined $self->{addFlagValuesToConfig};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"addFlagValuesToConfig"} 0 0 0
806  
807 # set/generate instance specific names
808 0 foreach my $entry (keys %{$config->{oct_config}->{instance_specific_name}}){
809 0 $config->{oct_config}->{instance_specific_name}->{$entry} .= "-$self->{instance}";
810 }
811  
812 0 $config->{allowed_clusters} = $config->{oct_config}->{project}->{allowed_clusters};
813 0 ▶ if(not defined $config->{allowed_clusters}){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $config->{'allowed_clusters'}) { } 0 0 0
814 0 print "INFO: oct_config->project->allowed_clusters json node is empty. Marking 'allowed_clusters' as '$self->{cluster}'\n";
815 0 $config->{allowed_clusters} = $self->{cluster};
816 }else{
817 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
818 }
819  
820 0 $config->{cluster_ip_range} = $config->{oct_config}->{project}->{cluster_ip_range};
821 0 ▶ $config->{cluster_ip_range} = $self->{clusterIpRange} if defined $self->{clusterIpRange};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"clusterIpRange"} 0 0 0
822 0 $config->{project_name} = $config->{oct_config}->{project}->{name};
823 0 ▶ $config->{project_name} = $self->{projectName} if defined $self->{projectName};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"projectName"} 0 0 0
824 0 $config->{host} = $config->{oct_config}->{project}->{host};
825 0 ▶ $config->{host} = $self->{host} if defined $self->{host};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"host"} 0 0 0
826 0 $config->{namespace} = $config->{oct_config}->{project}->{namespace};
827 0 ▶ $config->{namespace} = $self->{namespace} if defined $self->{namespace};# from -n flag
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"namespace"} 0 0 0
828 0 ▶ $config->{namespace} = $self->_getCurrentProject() if not defined $config->{namespace};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"namespace"} 0 0 0
829 # default component dirs are set here, dirs in 'templates_tt' not set as default will be omitted
830 0 $config->{component_dirs} = $config->{oct_config}->{project}->{component_dirs};
831 0 ▶ $config->{component_dirs} = $self->{components} if defined $self->{components};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"components"} 0 0 0
832 0 ▶ $config->{component_dirs} = $self->_getComponentsFromTemplatesTTDir() if not defined $config->{component_dirs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"component_dirs"} 0 0 0
833 # component dirs can contains numbers e.g.: '50-solr' so regexp match is used =>
834 # separate 'init' components in order to avoid false matches (e.g.: 20-init-api vs 50-api when 'api' searched)
835 0 my @components = split(';', $config->{component_dirs});
836 0 my $standardComponentDirs = "";
837 0 my $initComponentDirs = "";
838 0 foreach my $componentDir (@components){
839 0 ▶ if($componentDir =~ /init/){
Branch: 1 branch
BranchTrueFalseTotal
if ($componentDir =~ /init/u) { } 0 0 0
840 0 $initComponentDirs .= $componentDir.";";
841 }else{
842 0 $standardComponentDirs .= $componentDir.";";
843 }
844 }
845 0 chop($initComponentDirs);
846 0 chop($standardComponentDirs);
847 0 $config->{init_component_dirs} = $initComponentDirs;
848 0 $config->{standard_component_dirs} = $standardComponentDirs;
849 0 $config->{resource_kinds_backup} = $config->{oct_config}->{project}->{resource_kinds_backup};
850 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
851 0 $config->{resource_kinds} = $config->{oct_config}->{project}->{resource_kinds};
852 0 ▶ $config->{resource_kinds} = $self->{resourceKinds} if defined $self->{resourceKinds};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"resourceKinds"} 0 0 0
853 0 ▶ $config->{resource_kinds} = $self->_getDefaultKinds() if not defined $config->{resource_kinds};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"resource_kinds"} 0 0 0
854 0 $config->{templates_yaml_dir} = $self->{templatesYamlDir};
855 0 $config->{templates_tt_dir} = $self->{templatesTTDir};
856 0 $config->{cluster} = $self->{cluster};
857 0 $config->{instance} = $self->{instance};
858 0 $config->{instance_capitalized_first} = ucfirst $config->{instance};
859 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
860 0 ▶ $config->{url_prefix} = $self->{urlPrefix} if defined $self->{urlPrefix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"urlPrefix"} 0 0 0
861 0 ▶ $config->{cluster_base_address} = $self->{clusterBaseAddress} if defined $self->{clusterBaseAddress};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"clusterBaseAddress"} 0 0 0
862 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
863
864 0 my $componentConfigNodes = $self->_getComponentConfigNodes($config);
865 0 foreach my $componentConfNode (@$componentConfigNodes){
866 # set/generate default urls
867 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
868 (ref($config->{oct_config}->{instance_specific_data}->{$componentConfNode}) eq 'HASH')){
869 0 foreach my $instanceKey (keys %{$config->{oct_config}->{instance_specific_data}->{$componentConfNode}}){
870 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
871 0 my $componentNameKebab = $componentConfNode;
872 0 $componentNameKebab =~ s/_/\-/g;
873 0 my $lcInstanceKey = lc $instanceKey;
874 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
875 0 my $url = "";
876 0 ▶ if(defined $self->{generateUrl}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"generateUrl"}) 0 0 0
877 $url = $self->{generateUrl}->($config->{url_prefix},
878 $config->{project_name},
879 $componentNameKebab,
880 $lcInstanceKey,
881 $config->{cluster_base_address},
882 0 $config->{host});
883 }
884 0 $config->{oct_config}->{instance_specific_data}->{$componentConfNode}->{$instanceKey}->{url} = $url;
885 }
886 }
887 }
888 # select instance specific data
889 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
890 $config->{oct_config}->{instance_specific_data}->{$componentConfNode} =
891 0 $config->{oct_config}->{instance_specific_data}->{$componentConfNode}->{$self->{instance}};
892 }
893 }
894 # in worse case 36 available IP addresses(see _writeYamlFile), make number smaller if more needed(max is 256)
895 0 $config->{ip_last_number} = int(rand(220));
896
897 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
898 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
899 0 ▶ print "'Info: host' parameter is missing\n" if not defined $config->{host};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{"host"} 0 0 0
900  
901 0 return $config;
902 }
903  
904 0 ▶sub _getCurrentProject{
Subroutine _getCurrentProject: not called CC=2 SCAR=17.9
905 0 my ($self) = @_;
906  
907 0 my $projectCmdLine = qx/$self->{cloudCommand} config current-context/;
908 0 my @projectCmdLineArr = split('/', $projectCmdLine);
909 0 my $project = $projectCmdLineArr[0];
910 0 ▶ $project = "unknown" if not defined $project;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $project 0 0 0
911  
912 0 return $project;
913 }
914  
915 0 ▶sub _getDefaultKinds{
Subroutine _getDefaultKinds: not called CC=1 SCAR=6.9
916 0 return "PersistentVolumeClaim;ImageStream;BuildConfig;Deployment;DeploymentConfig;Secret;ConfigMap;CronJob;Job;Service;Route";
917 }
918  
919 0 ▶sub _getDefaultKindsBackup{
Subroutine _getDefaultKindsBackup: not called CC=1 SCAR=6.9
920 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";
921 }
922  
923 0 ▶sub _getSecrets{
Subroutine _getSecrets: not called CC=15 SCAR=54.8
924 0 my ($self, $config) = @_;
925  
926 0 my $secretJsonFileName = $self->{secretsJson};
927 # secrets files for all instances and all clusters e.g.: secrets/my-secret.txt
928 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in($self->{secretsDir})) {
929 0 my @dirFileNameArr = split('/', $dirFileName);
930 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
931 0 $self->_addSecretsToConfigHash($config, $dirFileName);
932 }
933  
934 # instance specific secrets files and for all clusters e.g.: secrets/instance/test/my-secret.txt
935 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in("$self->{secretsDir}/instance/$self->{instance}")) {
936 0 my @dirFileNameArr = split('/', $dirFileName);
937 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
938 0 $self->_addSecretsToConfigHash($config, $dirFileName);
939 }
940
941 0 my $clusterSpecificSecretsDirExist = 0;
942 0 foreach my $dirPath (glob "$self->{secretsDir}/*"){
943 0 ▶ next if not -d $dirPath;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dirPath 0 0 0
944 0 my @dirPathArr = split('/', $dirPath);
945 0 my $dirName = $dirPathArr[-1];
946 0 ▶ next if $dirName eq "instance";
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq "instance" 0 0 0
947 0 ▶ $clusterSpecificSecretsDirExist = 1 if $dirName eq $self->{config}->{cluster};
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq $self->{"config"}{"cluster"} 0 0 0
948 }
949
950 # secrets files for all instances and for specific cluster e.g.: secrets/clusterIntern/my_secret.txt
951 0 ▶ if($clusterSpecificSecretsDirExist){
Branch: 1 branch
BranchTrueFalseTotal
if ($clusterSpecificSecretsDirExist) 0 0 0
952 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in("$self->{secretsDir}/$self->{config}->{cluster}")) {
953 0 my @dirFileNameArr = split('/', $dirFileName);
954 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
955 0 $self->_addSecretsToConfigHash($config, $dirFileName);
956 }
957 # secret files for specific instance and specific cluster e.g.: secrets/clusterIntern/instance/prod/my_secret.txt
958 0 for my $dirFileName (File::Find::Rule->file()->name("*")->maxdepth(1)->in("$self->{secretsDir}/$self->{config}->{cluster}/instance/$self->{instance}")) {
959 0 my @dirFileNameArr = split('/', $dirFileName);
960 0 ▶ next if $dirFileNameArr[-1] eq $secretJsonFileName;
Branch: 1 branch
BranchTrueFalseTotal
if $dirFileNameArr[-1] eq $secretJsonFileName 0 0 0
961 0 $self->_addSecretsToConfigHash($config, $dirFileName);
962 }
963 }
964 # secrets json for all instances and all clusters
965 0 $config->{secrets_json} = {};
966 0 eval {
967 0 my $secretJson = read_file("$self->{secretsDir}/$secretJsonFileName");
968 0 my $secretJsonAllInstancesAllClustersHash = $self->{json}->utf8->decode($secretJson);
969 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonAllInstancesAllClustersHash);
970 };
971 0 ▶ if($clusterSpecificSecretsDirExist){
Branch: 1 branch
BranchTrueFalseTotal
if ($clusterSpecificSecretsDirExist) { } 0 0 0
972 # secrets json for all instances and specific cluster
973 0 my $path = "$self->{secretsDir}/$self->{config}->{cluster}/$secretJsonFileName";
974 0 eval {
975 0 my $secretJsonClusterSpecific = read_file($path);
976 0 my $secretJsonClusterSpecificHash = $self->{json}->utf8->decode($secretJsonClusterSpecific);
977 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonClusterSpecificHash);
978 };
979 # secrets json for specific instance and specific cluster
980 0 $path = "$self->{secretsDir}/$self->{config}->{cluster}/instance/$self->{instance}/$secretJsonFileName";
981 0 eval {
982 0 my $secretJsonClusterSpecificInstanceSpecific = read_file($path);
983 0 my $secretJsonClusterSpecificInstanceSpecificHash = $self->{json}->utf8->decode($secretJsonClusterSpecificInstanceSpecific);
984 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonClusterSpecificInstanceSpecificHash);
985 };
986 }else{
987 # secrets json for specific instance and all clusters
988 0 my $path = "$self->{secretsDir}/instance/$self->{instance}/$secretJsonFileName";
989 0 eval {
990 0 my $secretJsonInstanceSpecific = read_file($path);
991 0 my $secretJsonInstanceSpecificHash = $self->{json}->utf8->decode($secretJsonInstanceSpecific);
992 0 $self->_mergeSecretsJson($config->{secrets_json}, $secretJsonInstanceSpecificHash);
993 };
994 }
995  
996 0 return;
997 }
998  
999 0 ▶sub _getCloudWriteCommand{
Subroutine _getCloudWriteCommand: not called CC=6 SCAR=37.4
1000 0 my ($self) = @_;
1001  
1002 0 my $writeCommand = "create";
1003 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
1004 0 $writeCommand = $self->{config}->{oct_config}->{project}->{default_cloud_write_command};
1005 }
1006 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
1007 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
1008
1009 0 return $writeCommand;
1010 }
1011  
1012 0 ▶sub _gitCommitAndPush{
Subroutine _gitCommitAndPush: not called CC=8 SCAR=42.8
1013 0 my ($self, $instance) = @_;
1014  
1015 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
1016 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
1017 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");
1018 0 my $continue = <>;
1019 0 ▶ return if $continue =~ /skip/;
Branch: 1 branch
BranchTrueFalseTotal
if $continue =~ /skip/u 0 0 0
1020 }
1021 0 $self->_writeLog("commiting to git...\n");
1022 0 my $commitText = "committed on: " . localtime;
1023 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
1024 0 $self->_writeLog("Write your git commit message or press Enter to use default:\n($commitText)\n");
1025 0 my $customMsg = <>;
1026 0 ▶ $commitText = $customMsg if $customMsg ne "\n";
Branch: 1 branch
BranchTrueFalseTotal
if $customMsg ne "\n" 0 0 0
1027 0 $commitText =~ s/\n//g;
1028 }
1029 0 $self->_writeLog("git commit -am \"$commitText\"\n");
1030 0 `git commit -am "$commitText"`;
1031 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
1032 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
1033 0 $self->_writeLog("git push origin $branch\n");
1034 0 `git push origin $branch`;
1035 }
1036 }
1037  
1038 0 return;
1039 }
1040  
1041 0 ▶sub _initConfSecretsAndYaml{
Subroutine _initConfSecretsAndYaml: not called CC=2 SCAR=17.9
1042 0 my ($self, $instance) = @_;
1043
1044 0 $self->{instance} = $instance;
1045 0 $self->{config} = $self->_getConfig();
1046 0 $self->_runPreHook();
1047
1048 0 my $outputLogFile = "output.log";
1049 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
1050 0 $outputLogFile = $self->{config}->{oct_config}->{project}->{output_log_file};
1051 }
1052 0 `touch $outputLogFile`;
1053 0 `>$outputLogFile`; # clear file content
1054  
1055 0 $self->_getSecrets($self->{config});
1056 0 $self->_generateYaml();
1057
1058 0 return;
1059 }
1060  
1061 0 ▶sub _loopDir {
Subroutine _loopDir: not called CC=20 SCAR=58.0
1062 0 my ($self, $dirToLoop, $extention, $injectedSubName, $params) = @_;
1063  
1064 0 my $templates = {};
1065 0 for my $dirFileName (File::Find::Rule->file()->name("*.$extention")->in($dirToLoop)) {
1066 0 $dirFileName =~ s/$dirToLoop\///;
1067 0 my @dirFile = split('\/', $dirFileName);
1068 0 my @dir = split('\-', $dirFile[0]);
1069 0 my @file = split('\-', $dirFile[1]);
1070 # e.g: $templates->{30-solr}->{dirNumber} = 30 # in order so sort as integer
1071 # ->{20-build-config-solr.tt} = 20
1072 0 $templates->{$dirFile[0]}->{dirNumber} = $dir[0];
1073 0 $templates->{$dirFile[0]}->{$dirFile[1]} = $file[0];
1074 }
1075  
1076 0 my @dirArray;
1077 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
1078 0 foreach my $dir (sort { lc $templates->{$a}->{dirNumber} cmp lc $templates->{$b}->{dirNumber} } keys %{$templates}){
1079 0 push @dirArray, $dir;
1080 }
1081 }else{
1082 # numeric
1083 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1084 0 foreach my $dir (sort { $templates->{$a}->{dirNumber} <=> $templates->{$b}->{dirNumber} } keys %{$templates}){
1085 0 push @dirArray, $dir;
1086 }
1087 }
1088 0 ▶ @dirArray = reverse @dirArray if $injectedSubName eq "_deleteFromCloud";
Branch: 1 branch
BranchTrueFalseTotal
if $injectedSubName eq "_deleteFromCloud" 0 0 0
1089  
1090 0 foreach my $dir (@dirArray){
1091 0 ▶ $self->_writeLog("\nComponent: $dir:\n") if $injectedSubName eq "_callCloudCommand";
Branch: 1 branch
BranchTrueFalseTotal
if $injectedSubName eq "_callCloudCommand" 0 0 0
1092
1093 0 my @fileArray;
1094 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
1095 0 foreach my $file (sort { lc $templates->{$dir}->{$a} cmp lc $templates->{$dir}->{$b} } keys %{$templates->{$dir}}){
1096 0 push @fileArray, $file;
1097 }
1098 }else{
1099 # numeric
1100 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1101 0 foreach my $file (sort { $templates->{$dir}->{$a} <=> $templates->{$dir}->{$b} } keys %{$templates->{$dir}}){
1102 0 push @fileArray, $file;
1103 }
1104 }
1105 0 ▶ @fileArray = reverse @fileArray if $injectedSubName eq "_deleteFromCloud";
Branch: 1 branch
BranchTrueFalseTotal
if $injectedSubName eq "_deleteFromCloud" 0 0 0
1106 0 foreach my $file (@fileArray){
1107 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
1108 0 my @fileArr = split('\.', $file);
1109 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
1110 0 ▶ $self->_writeLog("Warning : Unknown cluster: $file\n") if $file ne "instance";
Branch: 1 branch
BranchTrueFalseTotal
if $file ne "instance" 0 0 0
1111 }
1112 0 my $injectedSub = \&$injectedSubName;
1113 0 $injectedSub->($self, {dir => $dir, templateName => $fileArr[0], params => $params});
1114 }
1115 }
1116 }
1117  
1118 0 ▶sub _mergeSecretsJson{
Subroutine _mergeSecretsJson: not called CC=3 SCAR=24.8
1119 0 my ($self, $jsonHashOriginal, $jsonHashAddition) = @_;
1120
1121 0 ▶ if(ref($jsonHashAddition) eq 'HASH'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $jsonHashAddition eq "HASH") 0 0 0
1122 0 foreach my $key (keys %{$jsonHashAddition}){
1123 0 $jsonHashOriginal->{$key} = $jsonHashAddition->{$key};
1124 0 $jsonHashOriginal->{base64}->{$key} = $self->_encodeJsonHashToBase64(dclone($jsonHashAddition->{$key}));
1125 }
1126 }
1127
1128 0 return;
1129 }
1130  
1131 0 ▶sub _removeInitFromComponentDirs{
Subroutine _removeInitFromComponentDirs: not called CC=1 SCAR=6.9
1132 0 my ($self) = @_;
1133
1134 0 my @componentsYamlDirArray = split(';', $self->{config}->{component_dirs});
1135 0 @componentsYamlDirArray = (grep {$_ !~ /init/} @componentsYamlDirArray);
1136 0 $self->{config}->{component_dirs} = join( ';', @componentsYamlDirArray);
1137 }
1138  
1139 0 ▶sub _runPreHook{
Subroutine _runPreHook: not called CC=4 SCAR=30.0
1140 0 my ($self) = @_;
1141
1142 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
1143 0 $self->{preHook}->($self->{config});
1144 }
1145  
1146 0 return;
1147 }
1148  
1149 0 ▶sub _runPostHook{
Subroutine _runPostHook: not called CC=4 SCAR=30.0
1150 0 my ($self) = @_;
1151  
1152 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
1153 0 $self->{postHook}->($self->{config});
1154 }
1155  
1156 0 return;
1157 }
1158  
1159 0 ▶sub _skipComponent{
Subroutine _skipComponent: not called CC=9 SCAR=45.0
1160 0 my ($self, $dir) = @_;
1161  
1162 # ignore skiping if called by this flag
1163 0 ▶ return 0 if defined $self->{yamlToTTconvertDir};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"yamlToTTconvertDir"} 0 0 0
1164
1165 0 my @installComponents = [];
1166 0 ▶ if($dir =~ /init/){
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /init/u) { } 0 0 0
1167 0 ▶ if(defined $self->{config}->{init_component_dirs}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"init_component_dirs"}) 0 0 0
1168 0 @installComponents = split(';', $self->{config}->{init_component_dirs});
1169 }
1170 0 foreach my $installComponent (@installComponents){
1171 0 ▶ return 0 if $dir =~ /$installComponent/;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ /$installComponent/u 0 0 0
1172 }
1173 }else{
1174 0 ▶ if(defined $self->{config}->{standard_component_dirs}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"standard_component_dirs"}) 0 0 0
1175 0 @installComponents = split(';', $self->{config}->{standard_component_dirs});
1176 }
1177 0 foreach my $installComponent (@installComponents){
1178 0 ▶ return 0 if $dir =~ /$installComponent/;
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ /$installComponent/u 0 0 0
1179 }
1180 }
1181  
1182 0 return 1;
1183 }
1184  
1185 0 ▶sub _validateAgainstCloud{
Subroutine _validateAgainstCloud: not called CC=16 SCAR=56.1
1186 0 my ($self, $params) = @_;
1187
1188 0 my @funcName = split /::/, (caller(0))[3];
1189 0 my $dir = $params->{dir};
1190 0 my $templateName = $params->{templateName};
1191  
1192 0 my $templateNameYaml = $templateName.".yaml";
1193 0 my $yamlData = LoadFile("$self->{config}->{templates_yaml_dir}/$dir/$templateNameYaml");
1194 0 my $octName = $yamlData->{metadata}->{name};
1195 0 my $octKind = $yamlData->{kind};
1196 0 my $octJson = qx/$self->{cloudCommand} get $octKind $octName -o json/;
1197 0 my $octHash = {};
1198 0 eval {
1199 0 $octHash = $self->{json}->utf8->decode($octJson);
1200 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
1201 0 foreach my $key (keys %{$octHash->{data}}){
1202 0 my $secret = decode_base64($octHash->{data}->{$key});
1203 0 $secret =~ s/\n//g;
1204 0 $secret =~ s/\r//g;
1205 0 $octHash->{data}->{$key} = $secret;
1206 }
1207 }
1208 };
1209 0 ▶ $self->_writeLog(Dumper($@)) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1210
1211 0 my $templateYamlText = read_file("$self->{config}->{templates_yaml_dir}/$dir/$templateNameYaml");
1212 0 my $yamlObj = YAML::Safe->new->boolean("JSON::PP");
1213 0 my $templateHash = $yamlObj->Load($templateYamlText);
1214 0 my $subParams = {"dir" => $dir, "templateName" => $templateName, "octKind" => $octKind, "octName" => $octName};
1215 0 ▶ $octHash = $self->{removeClutter}->($octHash, $subParams) if defined $self->{removeClutter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"removeClutter"} 0 0 0
1216 0 ▶ $templateHash = $self->{removeClutter}->($templateHash, $subParams) if defined $self->{removeClutter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"removeClutter"} 0 0 0
1217
1218 0 ▶ if($octKind eq "Secret"){
Branch: 1 branch
BranchTrueFalseTotal
if ($octKind eq "Secret") 0 0 0
1219 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
1220 0 foreach my $key (keys %{$templateHash->{data}}){
1221 0 my $dataBase64Encoded = $templateHash->{data}->{$key};
1222 0 my $dataBase64Decoded = decode_base64($dataBase64Encoded);
1223 0 $dataBase64Decoded =~ s/\n//g;
1224 0 $dataBase64Decoded =~ s/\r//g;
1225 0 $templateHash->{data}->{$key} = $dataBase64Decoded;
1226 }
1227 }
1228 }
1229
1230 0 $octJson = $self->{json}->utf8->pretty->canonical->encode($octHash);
1231 0 my $templateJson = $self->{json}->utf8->pretty->canonical->encode($templateHash);
1232 0 my @octJsonArr = split /\n/, $octJson;
1233 0 my @templateJsonArr = split /\n/, $templateJson;
1234 0 my $diff = diff \@octJsonArr, \@templateJsonArr, { STYLE => "Table", CONTEXT => 0 };
1235 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
1236 0 $diff = "+---+-----------------------------------------------------+---+---------------------------------+
1237 * | different secret, not displayed * | different secret, not displayed |
1238 +---+-----------------------------------------------------+---+---------------------------------+
1239 ";
1240 }
1241 0 $diff =~ s/\\ No newline at end of file\s//g;
1242
1243 0 my $diffStatus;
1244 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
1245 0 $diffStatus = "MODIFIED";
1246 0 $self->{"atLeastOneModified"} = 1;
1247 }else{
1248 0 $diffStatus = "OK";
1249 }
1250 0 my $line = "$dir/$templateNameYaml;$octKind;$octName;$diffStatus\n";
1251 0 $self->_writeLog($line);
1252 0 ▶ $self->_writeLog($diff) if $diff ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $diff ne "" 0 0 0
1253 0 write_file($self->{validationReportFile}, {append => 1}, $line);
1254 }
1255  
1256 # used only during cloud write operations(install/update/delete)
1257 0 ▶sub _writeLog{
Subroutine _writeLog: not called CC=2 SCAR=17.9
1258 0 my ($self, $text) = @_;
1259  
1260 0 print $text;
1261
1262 0 my $file = "output.log";
1263 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
1264 0 $file = $self->{config}->{oct_config}->{project}->{output_log_file};
1265 }
1266 0 write_file($file, {append => 1}, $text);
1267
1268 0 return;
1269 }
1270  
1271 0 ▶sub _writeYamlFile{
Subroutine _writeYamlFile: not called CC=18 SCAR=58.3
1272 0 my ($self, $params) = @_;
1273  
1274 0 my $dir = $params->{dir};
1275 0 my $templateName = $params->{templateName};
1276  
1277 # return if $dir =~ /init/ && (($self->{omit} // '') =~ /init/ || $self->{config}->{oct_config}->{project}->{omit_init});
1278
1279 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
1280 (
1281 ($self->{omit} // '') =~ /init/ ||
1282 ($self->{config}->{oct_config}->{project}->{omit_init} && ($self->{advanceFeatures} // '') !~ /useInit/)
1283 )
1284 ){
1285 0 return;
1286 }
1287
1288 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
1289 return if (defined $self->{componentIsAllowed}) &&
1290 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
1291
1292 0 my $yamlText;
1293 0 my $templatesYamlFilePath = "$self->{config}->{templates_yaml_dir}/$dir";
1294 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
1295  
1296 # $self->{templatesTTHash}->{"40-api"}->{"40-build-config-api"} = "40-api/clusterPublic/40-build-config-api";
1297 0 my $templateTTFilePath = "$self->{templatesTTDir}/$self->{templatesTTHash}->{$dir}->{$templateName}";
1298 0 $templateTTFilePath = $templateTTFilePath.".tt";
1299  
1300 0 eval { $self->{tt}->process($templateTTFilePath, $self->{config}, \$yamlText); };
1301 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1302 0 $self->_writeLog("Error occurred during generating yaml in: $dir $templateName\n".Dumper($@)."\n");
1303 0 return;
1304 }
1305  
1306 0 my $yamlHash;
1307 0 eval { $yamlHash = Load($yamlText);};
1308 0 ▶ if($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1309 0 $self->_writeLog("Error occurred during conversion to yaml in: $dir $templateName\n".Dumper($@)."\n");
1310 0 return;
1311 }
1312  
1313 0 $self->{templateManifests}->{$yamlHash->{kind}}->{$yamlHash->{metadata}->{name}} = 1;
1314
1315 0 my $allowedResourceKinds = $self->{config}->{resource_kinds};
1316 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
1317  
1318 0 write_file("$templatesYamlFilePath/$templateName\.yaml", $yamlText);
1319 0 ▶ $self->{config}->{ip_last_number}++ if $yamlHash->{kind} eq "Service";
Branch: 1 branch
BranchTrueFalseTotal
if $yamlHash->{"kind"} eq "Service" 0 0 0
1320 }
1321  
1322 0 ▶sub _writeYamlFiles{
Subroutine _writeYamlFiles: not called CC=7 SCAR=37.3
1323 0 my ($self) = @_;
1324  
1325 # $self->{templatesTTHash}->{"40-api"}->{"40-build-config-api"} = "40-api/clusterPublic/40-build-config-api.tt";
1326 0 my $dirs = $self->{templatesTTHash};
1327 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
1328 # alphabetic
1329 0 foreach my $dir (sort {lc($a) cmp lc($b)} keys %{$dirs}){
1330 0 my $files = $dirs->{$dir};
1331 0 foreach my $templateName (sort {lc($a) cmp lc($b)} keys %{$files}){
1332 0 $self->_writeYamlFile({dir => $dir, templateName => $templateName});
1333 }
1334 }
1335 }else{
1336 # numeric
1337 1 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
1338 0 foreach my $dir (sort {lc($a) <=> lc($b)} keys %{$dirs}){
1339 0 my $files = $dirs->{$dir};
1340 0 foreach my $templateName (sort {lc($a) <=> lc($b)} keys %{$files}){
1341 0 $self->_writeYamlFile({dir => $dir, templateName => $templateName});
1342 }
1343 }
1344 }
1345  
1346 0 return;
1347 }
1348  
1349 1 1;
1350  
1351 __END__
↑ Summary