diff --git a/.github/workflows/ci-service.yml b/.github/workflows/ci-service.yml index 17061a1cc0..21a6bc72fc 100644 --- a/.github/workflows/ci-service.yml +++ b/.github/workflows/ci-service.yml @@ -86,6 +86,7 @@ jobs: yast2-proxy yast2-storage-ng yast2-users + python3-jsonschema - name: Install RubyGems dependencies run: bundle config set --local with 'development' && bundle install diff --git a/service/lib/agama/autoyast/converter.rb b/service/lib/agama/autoyast/converter.rb index b2cad924e6..64540ab36f 100755 --- a/service/lib/agama/autoyast/converter.rb +++ b/service/lib/agama/autoyast/converter.rb @@ -63,7 +63,7 @@ def to_agama(dir) FileUtils.mkdir_p(path) import_yast profile = read_profile - File.write(path.join("autoinst.json"), export_profile(profile).to_json) + File.write(path.join("autoinst.json"), JSON.pretty_generate(export_profile(profile))) end private diff --git a/service/lib/agama/autoyast/l10n_reader.rb b/service/lib/agama/autoyast/l10n_reader.rb index 771db35cdf..7765c1f285 100755 --- a/service/lib/agama/autoyast/l10n_reader.rb +++ b/service/lib/agama/autoyast/l10n_reader.rb @@ -37,12 +37,12 @@ def initialize(profile) # # If there is no l10n information, it returns an empty hash. # - # @return [Hash] Agama "l10n" section + # @return [Hash] Agama "localization" section def read l10n = keyboard .merge(languages) .merge(timezone) - l10n.empty? ? {} : { "l10n" => l10n } + l10n.empty? ? {} : { "localization" => l10n } end private diff --git a/service/lib/agama/autoyast/scripts_reader.rb b/service/lib/agama/autoyast/scripts_reader.rb index 78ddb8b55a..f4d41aaa3c 100755 --- a/service/lib/agama/autoyast/scripts_reader.rb +++ b/service/lib/agama/autoyast/scripts_reader.rb @@ -44,6 +44,7 @@ class ScriptsReader # @param profile [ProfileHash] AutoYaST profile def initialize(profile) @profile = profile + @anonymous_counter = 0 end # Returns a hash that corresponds to Agama "scripts" section. @@ -100,10 +101,10 @@ def read_init_scripts # @param section [Hash] AutoYaST script section def read_script(section) script = { - "name" => section["file_name"] + "name" => section["filename"] || "annonymous#{@anonymous_counter += 1}" } - if section["location"] + if section["location"] && !section["location"].empty? script["url"] = section["location"] elsif section["source"] script["body"] = section["source"] diff --git a/service/test/agama/autoyast/converter_test.rb b/service/test/agama/autoyast/converter_test.rb index 44256439c5..40f161403c 100644 --- a/service/test/agama/autoyast/converter_test.rb +++ b/service/test/agama/autoyast/converter_test.rb @@ -40,8 +40,9 @@ end let(:xml_valid?) { true } let(:xml_errors) { [] } + let(:result_path) { File.join(workdir, "autoinst.json") } let(:result) do - content = File.read(File.join(workdir, "autoinst.json")) + content = File.read(result_path) JSON.parse(content) end let(:storage_manager) do @@ -109,7 +110,7 @@ it "evaluates the ERB code" do subject.to_agama(workdir) - expect(result["l10n"]).to include( + expect(result["localization"]).to include( "languages" => ["en_US.UTF-8", "es_ES.UTF-8"] ) end @@ -157,9 +158,9 @@ end end - it "exports l10n settings" do + it "exports localization settings" do subject.to_agama(workdir) - expect(result["l10n"]).to include( + expect(result["localization"]).to include( "languages" => ["en_US.UTF-8"], "timezone" => "Atlantic/Canary", "keyboard" => "us" @@ -177,4 +178,29 @@ subject.to_agama(workdir) end end + + context "for cloned profile" do + let(:profile_name) { "cloned.xml" } + + it "generate json according to schema" do + # sadly rubygem-json-schema cannot be used due to too old supported format + if !system("which jsonschema") + pending "can run only if python3-jsonschema is installed" + break + end + + subject.to_agama(workdir) + + schema = File.expand_path( + "../../../../rust/agama-lib/share/profile.schema.json", + __dir__ + ) + + # filter out deprecation warning as check-jsonschema is not packaged for TW yet + result = `jsonschema -i '#{result_path}' '#{schema}' 2>&1 | \ + grep -v 'DeprecationWarning' | \ + grep -v 'from jsonschema.cli import main'` + expect(result).to eq "" + end + end end diff --git a/service/test/agama/autoyast/l10n_reader_test.rb b/service/test/agama/autoyast/l10n_reader_test.rb index e2ea123825..57e5e2b85e 100644 --- a/service/test/agama/autoyast/l10n_reader_test.rb +++ b/service/test/agama/autoyast/l10n_reader_test.rb @@ -30,6 +30,8 @@ {} end + let(:l10n) { subject.read["localization"] } + subject do described_class.new(Yast::ProfileHash.new(profile)) end @@ -49,7 +51,6 @@ end it "includes a 'keyboard' key with its value" do - l10n = subject.read["l10n"] expect(l10n["keyboard"]).to eq("us") end end @@ -65,7 +66,6 @@ end it "includes a 'languages' key with all the languages" do - l10n = subject.read["l10n"] expect(l10n["languages"]).to eq(["en_US.UTF-8", "es_ES.UTF-8", "cs_CZ.UTF-8"]) end @@ -80,7 +80,6 @@ end it "uses the UTF-8 encoding" do - l10n = subject.read["l10n"] expect(l10n["languages"]).to eq(["en_US.UTF-8", "es_ES.UTF-8"]) end end @@ -92,7 +91,6 @@ end it "includes a 'keyboard' key with its value" do - l10n = subject.read["l10n"] expect(l10n["timezone"]).to eq("Europe/Berlin") end end diff --git a/service/test/agama/autoyast/scripts_reader_test.rb b/service/test/agama/autoyast/scripts_reader_test.rb index e1c7497834..df15396942 100644 --- a/service/test/agama/autoyast/scripts_reader_test.rb +++ b/service/test/agama/autoyast/scripts_reader_test.rb @@ -32,8 +32,8 @@ context "when the script definition includes the sources" do let(:script) do - { "file_name" => "script.sh", - "location" => "https://example.com/script.sh" } + { "filename" => "script.sh", + "location" => "https://example.com/script.sh" } end it "sets the \"url\" to the \"location\"" do @@ -45,8 +45,8 @@ context "when the script definition specifies a location" do let(:script) do { - "file_name" => "script.sh", - "source" => "#!/bin/bash\necho 'Hello World!'" + "filename" => "script.sh", + "source" => "#!/bin/bash\necho 'Hello World!'" } end @@ -77,9 +77,9 @@ it_behaves_like "a script reader", "chroot-scripts", "post" let(:chroot_script) do - { "file_name" => "test.sh", - "chrooted" => true, - "source" => "#!/bin/bash\necho 'Hello World!'" } + { "filename" => "test.sh", + "chrooted" => true, + "source" => "#!/bin/bash\necho 'Hello World!'" } end let(:profile) do @@ -92,8 +92,8 @@ context "when the \"chrooted\" option is not set" do let(:chroot_script) do - { "file_name" => "test.sh", - "source" => "#!/bin/bash\necho 'Hello World!'" } + { "filename" => "test.sh", + "source" => "#!/bin/bash\necho 'Hello World!'" } end it "sets the \"chroot\" option to false" do diff --git a/service/test/fixtures/profiles/cloned.xml b/service/test/fixtures/profiles/cloned.xml new file mode 100644 index 0000000000..e04c117c65 --- /dev/null +++ b/service/test/fixtures/profiles/cloned.xml @@ -0,0 +1,1146 @@ + + + + + + splash=silent mitigations=auto quiet security=apparmor crashkernel=309M,high + auto + auto + false + false + true + gfxterm + 8 + false + true + vga=gfx-1024x768x16 crashkernel=309M\<4G + + grub2 + + + public + true + off + true + + + Unsolicited incoming network packets are rejected. Incoming packets that are related to outgoing network connections are accepted. Outgoing network connections are allowed. + + false + block + + + + Block + %%REJECT%% + + + For computers in your demilitarized zone that are publicly-accessible with limited access to your internal network. Only selected incoming connections are accepted. + + false + dmz + + + + ssh + + DMZ + default + + + All network connections are accepted. + + docker0 + + false + docker + + + + docker + ACCEPT + + + Unsolicited incoming network packets are dropped. Incoming packets that are related to outgoing network connections are accepted. Outgoing network connections are allowed. + + false + drop + + + + Drop + DROP + + + For use on external networks. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + true + external + + + + ssh + + External + default + + + For use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + false + home + + + + dhcpv6-client + mdns + samba-client + ssh + + Home + default + + + For use on internal networks. You mostly trust the other computers on the networks to not harm your computer. Only selected incoming connections are accepted. + + false + internal + + + + dhcpv6-client + mdns + samba-client + ssh + + Internal + default + + + For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + eth0 + + false + public + + + + dhcpv6-client + ssh + + Public + default + + + All network connections are accepted. + + false + trusted + + + + Trusted + ACCEPT + + + For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted. + + false + work + + + + dhcpv6-client + ssh + + Work + default + + + + + + false + + + + + 100 + users + + + + 483 + video + + + + 71 + ntadmin + + + + 486 + render + + + + 496 + systemd-timesync + + + + 479 + chrony + + + + 62 + man + + + + 473 + sshd + + + + 65533 + nogroup + + + + 51 + postfix + + + + 482 + mail + postfix + + + 492 + audio + + + + 475 + polkitd + + + + 481 + wheel + + + + 15 + shadow + vnc + + + 5 + tty + + + + 493 + utmp + + + + 36 + kvm + + + + 1 + bin + daemon + + + 59 + maildrop + postfix + + + 472 + vnc + + + + 487 + lp + + + + 477 + nscd + + + + 489 + disk + + + + 499 + messagebus + + + + 494 + lock + + + + 488 + input + + + + 480 + audit + + + + 2 + daemon + + + + 495 + kmem + + + + 484 + tape + + + + 498 + systemd-journal + + + + 491 + cdrom + + + + 0 + root + + + + 478 + systemd-coredump + + + + 497 + systemd-network + + + + 42 + trusted + + + + 65534 + nobody + + + + 485 + sgx + + + + 490 + dialout + + + + + + + 127.0.0.1 + + localhost + + + + ::1 + + localhost ipv6-localhost ipv6-loopback + + + + fe00::0 + + ipv6-localnet + + + + ff00::0 + + ipv6-mcastprefix + + + + ff02::1 + + ipv6-allnodes + + + + ff02::2 + + ipv6-allrouters + + + + ff02::3 + + ipv6-allhosts + + + + + + true + 309M,high + 309M\<4G + + + no + + + true + yes + + lzo + 31 + 64 + + yes + 5 + + auto + 30 + + + + + + /var/crash + + + + + 3 + + + + + + + AUTO + + + true + dhcp213 + auto + + + + dhcp + eth0 + auto + public + + + true + true + false + + + eth0 + KERNELS + 0000:00:03.0 + + + + false + false + + + + auto + + +
2.suse.pool.ntp.org
+ true + false +
+
+ manual +
+ + + /dev/system + true + + + true + xfs + false + home + /home + device + false + false + 5792333824 + 1 + 0 + + + true + true + btrfs + false + root + / + device + false + true + false + 13522436096 + 1 + 0 + + + false + var + + + true + usr/local + + + true + tmp + + + true + srv + + + true + root + + + true + opt + + + true + boot/grub2/x86_64-efi + + + true + boot/grub2/i386-pc + + + @ + + + true + swap + false + swap + swap + device + false + false + 2147483648 + 1 + 0 + + + 4194304 + CT_LVM + + + /dev/sda + gpt + + + true + false + 263 + 1 + false + 8388608 + + + true + false + system + 142 + 2 + false + 21465382400 + + + CT_DISK + all + + + + false + + + reboot + /usr/lib/cracklib_dict + no + no + insecure + 3 + 60000 + 1000 + active_console + 184 + apparmor + secure + 0 + 0 + 0 + 99999 + 0 + 5 + 7 + sha512 + 0 + yes + easy + + no + 499 + 100 + 499 + 100 + no + 60000 + 1000 + /usr/sbin/useradd.local + /usr/sbin/userdel-post.local + /usr/sbin/userdel-pre.local + + + multi-user + + + YaST2-Firstboot + YaST2-Second-Stage + apparmor + auditd + klog + cron + firewalld + wickedd-auto4 + wickedd-dhcp4 + wickedd-dhcp6 + wickedd-nanny + display-manager + irqbalance + issue-generator + kbdsettings + kdump + kdump-early + lvm2-monitor + wicked + nscd + postfix + purge-kernels + rollback + rsyslog + smartd + sshd + systemd-pstore + systemd-remount-fs + + + + + true + + + xfsprogs + wicked + snapper + sles-release + sle-module-server-applications-release + sle-module-basesystem-release + openssh + numactl + lvm2 + kexec-tools + kdump + irqbalance + grub2 + glibc + firewalld + e2fsprogs + btrfsprogs + autoyast2 + + + apparmor + base + basic_desktop + enhanced_base + minimal_base + x11 + x11_yast + yast2_basis + + + SLES + + + + false + false + + + false + + + America/New_York + + + + 100 + /home + -1 + /bin/bash + 022 + + + + + true + tux + 100 + /home/tux + false + + + + + 99999 + 0 + 7 + + /bin/bash + 1000 + $6$epM6.b193j7ZvUaw$/oMPS9pQR9X9i1MAJag20ZFy0XSI4985uVQDGLugwoCbDJVoXKCWLMFM.WncHr/bpkjecwb.LLaJeheYatq8f. + tux + + + true + bin + 1 + /bin + false + + + + + + + + + /usr/sbin/nologin + 1 + ! + bin + + + true + systemd Network Management + 497 + / + false + + + + + + + + + /usr/sbin/nologin + 497 + !* + systemd-network + + + true + systemd Core Dumper + 478 + / + false + + + + + + + + + /usr/sbin/nologin + 478 + !* + systemd-coredump + + + + true + root + 0 + /root + false + + + + + + + + + /bin/bash + 0 + $6$sxZ921ci.szwhCIw$9lrLQTtanJcpPeJkqv9pU0LsKQLO3RcPhBPBDMfc1uGUDCfgiyEyGPNr/ZKXAgqZsL61DANvr4uAYYDkif/Ma0 + root + + + true + user for rpcbind + 65534 + /var/lib/empty + false + + + + + + + + + /sbin/nologin + 477 + ! + rpc + + + true + Printing daemon + 487 + /var/spool/lpd + false + + + + + + + + + /usr/sbin/nologin + 494 + ! + lp + + + true + User for nscd + 477 + /run/nscd + false + + + + + + + + + /sbin/nologin + 476 + ! + nscd + + + true + nobody + 65534 + /var/lib/nobody + false + + + + + + + + + /bin/bash + 65534 + ! + nobody + + + true + user for VNC + 472 + /var/lib/empty + false + + + + + + + + + /usr/sbin/nologin + 472 + ! + vnc + + + true + Manual pages viewer + 62 + /var/lib/empty + false + + + + + + + + + /usr/sbin/nologin + 13 + ! + man + + + true + SSH daemon + 473 + /var/lib/sshd + false + + + + + + + + + /usr/sbin/nologin + 473 + ! + sshd + + + true + Daemon + 2 + /sbin + false + + + + + + + + + /usr/sbin/nologin + 2 + ! + daemon + + + true + Chrony Daemon + 479 + /var/lib/chrony + false + + + + + + + + + /usr/sbin/nologin + 493 + ! + chrony + + + true + systemd Time Synchronization + 496 + / + false + + + + + + + + + /usr/sbin/nologin + 496 + !* + systemd-timesync + + + true + NFS statd daemon + 65533 + /var/lib/nfs + false + + + + + + + + + /sbin/nologin + 474 + ! + statd + + + true + User for D-Bus + 499 + /run/dbus + false + + + + + + + + + /usr/bin/false + 499 + ! + messagebus + + + true + User for polkitd + 475 + /var/lib/polkit + false + + + + + + + + + /usr/sbin/nologin + 475 + ! + polkitd + + + true + Mailer daemon + 482 + /var/spool/clientmqueue + false + + + + + + + + + /usr/sbin/nologin + 495 + ! + mail + + + true + Postfix Daemon + 51 + /var/spool/postfix + false + + + + + + + + + /usr/sbin/nologin + 51 + ! + postfix + + + + + + + + +