tpkg 2.3.3 → 2.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/Portfile +39 -0
  6. data/Portfile.template +39 -0
  7. data/README.md +43 -0
  8. data/Rakefile +468 -18
  9. data/bin/gem2tpkg +2 -2
  10. data/bin/tpkg +18 -13
  11. data/bin/tpkg_uploader +132 -0
  12. data/ca.pem +1 -0
  13. data/control +7 -0
  14. data/depend +3 -0
  15. data/externals-etch/authorized_keys +40 -0
  16. data/externals-etch/group +9 -0
  17. data/externals-etch/iptables +38 -0
  18. data/externals-etch/limits +30 -0
  19. data/externals-etch/nfs +30 -0
  20. data/externals-etch/sudo +30 -0
  21. data/externals-etch/supplemental_groups +8 -0
  22. data/externals-etch/sysctl +30 -0
  23. data/externals-etch/user +41 -0
  24. data/externals/group +39 -0
  25. data/externals/supplemental_groups +48 -0
  26. data/externals/user +39 -0
  27. data/lib/tpkg.rb +260 -991
  28. data/lib/tpkg/os.rb +164 -0
  29. data/lib/tpkg/os/debian.rb +159 -0
  30. data/lib/tpkg/os/freebsd.rb +113 -0
  31. data/lib/tpkg/os/macosx.rb +113 -0
  32. data/lib/tpkg/os/redhat.rb +173 -0
  33. data/lib/tpkg/os/solaris.rb +101 -0
  34. data/lib/tpkg/os/windows.rb +26 -0
  35. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
  36. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
  37. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
  38. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
  39. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
  40. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
  41. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
  42. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
  43. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
  44. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
  45. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
  46. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
  47. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
  48. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
  49. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
  50. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
  51. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
  52. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
  53. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
  54. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
  55. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
  56. data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
  57. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
  58. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
  59. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
  60. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
  61. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
  62. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
  63. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
  64. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
  65. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
  66. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
  67. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
  68. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
  69. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
  70. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
  71. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
  72. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
  73. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
  74. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
  75. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
  76. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
  77. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
  78. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
  79. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
  80. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
  81. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
  82. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
  83. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
  84. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
  85. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
  86. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
  87. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
  88. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
  89. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
  90. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
  91. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
  92. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
  93. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
  94. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
  95. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
  96. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
  97. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
  98. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
  99. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
  100. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
  101. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
  102. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
  103. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
  104. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
  105. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
  106. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
  107. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
  108. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
  109. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
  110. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
  111. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
  112. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
  113. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
  114. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
  115. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
  116. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
  117. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
  118. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
  119. data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
  120. data/lib/tpkg/version.rb +3 -0
  121. data/man/man1/cpan2tpkg.1 +82 -0
  122. data/man/man1/gem2tpkg.1 +120 -0
  123. data/man/man1/tpkg.1 +411 -0
  124. data/pkginfo +8 -0
  125. data/postinstall.solaris +11 -0
  126. data/postremove.solaris +16 -0
  127. data/schema/schema-1.0.5.yml +0 -0
  128. data/schema/schema-1.0.6.yml +0 -0
  129. data/schema/schema-1.0.7.yml +0 -0
  130. data/schema/schema-1.0.8.yml +0 -0
  131. data/schema/schema-1.0.9.yml +0 -0
  132. data/schema/schema.yml +0 -0
  133. data/schema/tpkg-1.0.0.dtd +0 -0
  134. data/schema/tpkg-1.0.1.dtd +0 -0
  135. data/schema/tpkg-1.0.2.dtd +0 -0
  136. data/schema/tpkg-1.0.3.dtd +0 -0
  137. data/schema/tpkg-1.0.4.dtd +0 -0
  138. data/schema/tpkg-1.0.5.dtd +0 -0
  139. data/schema/tpkg-1.0.6.dtd +0 -0
  140. data/schema/tpkg-1.0.7.dtd +0 -0
  141. data/schema/tpkg-1.0.8.dtd +0 -0
  142. data/schema/tpkg-1.0.9.dtd +0 -0
  143. data/schema/tpkg.dtd +0 -0
  144. data/test/TODO +30 -0
  145. data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
  146. data/test/test_checksum.rb +53 -0
  147. data/test/test_compress.rb +55 -0
  148. data/test/test_conflict.rb +41 -0
  149. data/test/test_crontabs.rb +398 -0
  150. data/test/test_dependency.rb +1113 -0
  151. data/test/test_downgrade.rb +80 -0
  152. data/test/test_download.rb +95 -0
  153. data/test/test_encrypt.rb +136 -0
  154. data/test/test_filemetadata.rb +131 -0
  155. data/test/test_initscript.rb +93 -0
  156. data/test/test_install.rb +186 -0
  157. data/test/test_lock.rb +82 -0
  158. data/test/test_make.rb +410 -0
  159. data/test/test_metadata.rb +805 -0
  160. data/test/test_misc.rb +379 -0
  161. data/test/test_options.rb +1711 -0
  162. data/test/test_os.rb +193 -0
  163. data/test/test_os_debian.rb +99 -0
  164. data/test/test_os_freebsd.rb +89 -0
  165. data/test/test_os_macosx.rb +79 -0
  166. data/test/test_os_redhat.rb +124 -0
  167. data/test/test_os_solaris.rb +85 -0
  168. data/test/test_os_windows.rb +26 -0
  169. data/test/test_query.rb +134 -0
  170. data/test/test_remove.rb +539 -0
  171. data/test/test_tar.rb +99 -0
  172. data/test/test_unpack.rb +977 -0
  173. data/test/test_upgrade.rb +398 -0
  174. data/test/test_version.rb +54 -0
  175. data/test/testcmds/crontab +14 -0
  176. data/test/testcmds/debian/apt-cache +145 -0
  177. data/test/testcmds/debian/dpkg-query +16 -0
  178. data/test/testcmds/freebsd/pkg_info +13 -0
  179. data/test/testcmds/macosx/port +35 -0
  180. data/test/testcmds/redhat/rpmbuild +6 -0
  181. data/test/testcmds/redhat/yum +90 -0
  182. data/test/testcmds/solaris/pkginfo +25 -0
  183. data/test/testcmds/solaris/pkgutil +36 -0
  184. data/test/testpkg/reloc/encfile +2 -0
  185. data/test/testpkg/reloc/file +2 -0
  186. data/test/testpkg/reloc/precryptfile +1 -0
  187. data/test/testpkg/reloc/precryptfile.plaintext +3 -0
  188. data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
  189. data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
  190. data/test/testpkg/tpkg-default-perms.xml +28 -0
  191. data/test/testpkg/tpkg-default-perms.yml +20 -0
  192. data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
  193. data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
  194. data/test/testpkg/tpkg-nativedeps.yml +13 -0
  195. data/test/testpkg/tpkg-nofiles.xml +14 -0
  196. data/test/testpkg/tpkg-nofiles.yml +9 -0
  197. data/test/testpkg/tpkg.xml +35 -0
  198. data/test/testpkg/tpkg.yml +25 -0
  199. data/test/tpkgtest.rb +300 -0
  200. data/tpkg.conf +16 -0
  201. data/tpkg.gemspec +24 -0
  202. data/tpkg.spec +28 -0
  203. data/tpkg.xml +17 -0
  204. data/tpkg_profile.sh +32 -0
  205. metadata +306 -31
@@ -0,0 +1,124 @@
1
+ #
2
+ # Tests Red Hat OS abstraction code
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ # Make private methods public so that we can test them
8
+ class Tpkg::OS::RedHat
9
+ public :create_rpm
10
+ end
11
+
12
+ class TpkgOSRedHatTests < Test::Unit::TestCase
13
+ include TpkgTests
14
+
15
+ def setup
16
+ @redhat = Tpkg::OS::RedHat.new(
17
+ :yumcmd => File.join(TESTCMDDIR, 'redhat/yum'),
18
+ )
19
+ end
20
+
21
+ def test_supported
22
+ fact = Facter::Util::Fact.new('operatingsystem')
23
+ Facter.stubs(:[]).returns(fact)
24
+ fact.stubs(:value).returns('RedHat')
25
+ assert Tpkg::OS::RedHat.supported?
26
+ fact.stubs(:value).returns('CentOS')
27
+ assert Tpkg::OS::RedHat.supported?
28
+ fact.stubs(:value).returns('Fedora')
29
+ assert Tpkg::OS::RedHat.supported?
30
+ fact.stubs(:value).returns('Other')
31
+ refute Tpkg::OS::RedHat.supported?
32
+ end
33
+ def test_initialize
34
+ [:yumcmd, :rpmcmd, :rpmbuildcmd].each do |cmdvar|
35
+ redhat = Tpkg::OS::RedHat.new(cmdvar => TESTCMD)
36
+ assert_equal TESTCMD, redhat.instance_variable_get("@#{cmdvar}")
37
+ redhat = Tpkg::OS::RedHat.new(:testcmd => TESTCMD)
38
+ assert_equal TESTCMD, redhat.instance_variable_get("@#{cmdvar}")
39
+ end
40
+ [true, false].each do |quietval|
41
+ redhat = Tpkg::OS::RedHat.new(:quiet => quietval)
42
+ assert_equal quietval, redhat.instance_variable_get(:@quiet)
43
+ end
44
+ # Test that super is called
45
+ [true, false].each do |debugval|
46
+ redhat = Tpkg::OS::RedHat.new(:debug => debugval)
47
+ assert_equal debugval, redhat.instance_variable_get(:@debug)
48
+ end
49
+ end
50
+ def test_init_links
51
+ correct = (2..5).collect{|i| "/etc/rc.d/rc#{i}.d/S99script"}
52
+ assert_equal correct, @redhat.init_links('/path/to/init/script', {:init => {}})
53
+ end
54
+ def test_cron_dot_d_directory
55
+ assert_equal '/etc/cron.d', @redhat.cron_dot_d_directory
56
+ end
57
+ def test_available_native_packages
58
+ assert_equal(
59
+ [
60
+ {:metadata=>
61
+ {:name=>'curl', :version=>'7.19.7', :package_version=>'26.el6_2.4'},
62
+ :source=>:native_installed,
63
+ :prefer=>true},
64
+ ],
65
+ @redhat.available_native_packages('curl'))
66
+ assert_equal(
67
+ [
68
+ {:metadata=>
69
+ {:name=>'wget', :version=>'1.12', :package_version=>'1.4.el6'},
70
+ :source=>:native_available}
71
+ ],
72
+ @redhat.available_native_packages('wget'))
73
+ assert_equal [], @redhat.available_native_packages('bogus')
74
+ end
75
+ def test_install_native_package
76
+ redhat = Tpkg::OS::RedHat.new
77
+ redhat.expects(:system).with('yum -y install curl-7.19.7-26.el6_2.4')
78
+ redhat.install_native_package(
79
+ {:metadata => {:name => 'curl', :version => '7.19.7', :package_version => '26.el6_2.4'}})
80
+ end
81
+ def test_upgrade_native_package
82
+ redhat = Tpkg::OS::RedHat.new
83
+ redhat.expects(:system).with('yum -y install curl-7.19.7-26.el6_2.4')
84
+ redhat.install_native_package(
85
+ {:metadata => {:name => 'curl', :version => '7.19.7', :package_version => '26.el6_2.4'}})
86
+ end
87
+ def test_stub_native_pkg
88
+ metafile = File.join(TESTPKGDIR, 'tpkg-nativedeps.yml')
89
+ metatext = File.read(metafile)
90
+ metadata = Metadata.new(metatext, 'yml')
91
+ redhat = Tpkg::OS::RedHat.new(
92
+ :rpmbuildcmd => File.join(TESTCMDDIR, 'redhat/rpmbuild'))
93
+ redhat.expects(:create_rpm).returns('/path/to/rpm.rpm')
94
+ redhat.expects(:system).with('rpm -i /path/to/rpm.rpm')
95
+ redhat.stub_native_pkg({:metadata => metadata})
96
+ end
97
+ def test_remove_native_stub_pkg
98
+ metafile = File.join(TESTPKGDIR, 'tpkg-nativedeps.yml')
99
+ metatext = File.read(metafile)
100
+ metadata = Metadata.new(metatext, 'yml')
101
+ redhat = Tpkg::OS::RedHat.new
102
+ redhat.expects(:system).with('yum -y remove stub_for_testpkg')
103
+ redhat.remove_native_stub_pkg({:metadata => metadata})
104
+ end
105
+ def test_os_version
106
+ fact = Facter::Util::Fact.new('lsbmajdistrelease')
107
+ fact.stubs(:value).returns('6')
108
+ Facter.expects(:[]).with('lsbmajdistrelease').returns(fact).at_least_once
109
+ assert_equal '6', Tpkg::OS::RedHat.new.os_version
110
+ end
111
+ def test_create_rpm
112
+ # Test that rpmbuild is called with reasonable arguments
113
+ redhat = Tpkg::OS::RedHat.new(:quiet => true)
114
+ redhat.expects(:system).
115
+ with(regexp_matches(%r{rpmbuild -bb --define '_topdir .*' .*/SPECS/pkg.spec}))
116
+ redhat.create_rpm('test', [{:name => 'dep1'}, {:name => 'dep2'}])
117
+ # Test that, with a fake rpmbuild, the method produces the expected result
118
+ redhat = Tpkg::OS::RedHat.new(
119
+ :rpmbuildcmd => File.join(TESTCMDDIR, 'redhat/rpmbuild'))
120
+ fakerpm = redhat.create_rpm('test', [{:name => 'dep1'}, {:name => 'dep2'}])
121
+ assert_equal 'This is a fake rpm', File.read(fakerpm)
122
+ FileUtils.rm_f(fakerpm)
123
+ end
124
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Tests Solaris OS abstraction code
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ class TpkgOSSolarisTests < Test::Unit::TestCase
8
+ include TpkgTests
9
+
10
+ def setup
11
+ @pkginfo = File.join(TESTCMDDIR, 'solaris/pkginfo')
12
+ @pkgutil = File.join(TESTCMDDIR, 'solaris/pkgutil')
13
+ @solaris = Tpkg::OS::Solaris.new(
14
+ :pkginfocmd => @pkginfo,
15
+ :pkgutilcmd => @pkgutil,
16
+ )
17
+ end
18
+
19
+ def test_supported
20
+ fact = Facter::Util::Fact.new('operatingsystem')
21
+ Facter.expects(:[]).with('operatingsystem').returns(fact).at_least_once
22
+ fact.stubs(:value).returns('Solaris')
23
+ assert Tpkg::OS::Solaris.supported?
24
+ fact.stubs(:value).returns('Other')
25
+ refute Tpkg::OS::Solaris.supported?
26
+ end
27
+ def test_initialize
28
+ [:pkginfocmd, :pkgutilcmd].each do |cmdvar|
29
+ solaris = Tpkg::OS::Solaris.new(cmdvar => TESTCMD)
30
+ assert_equal TESTCMD, solaris.instance_variable_get("@#{cmdvar}")
31
+ solaris = Tpkg::OS::Solaris.new(:testcmd => TESTCMD)
32
+ assert_equal TESTCMD, solaris.instance_variable_get("@#{cmdvar}")
33
+ end
34
+ # Test that super is called
35
+ [true, false].each do |debugval|
36
+ solaris = Tpkg::OS::Solaris.new(:debug => debugval)
37
+ assert_equal debugval, solaris.instance_variable_get(:@debug)
38
+ end
39
+ end
40
+ def test_init_links
41
+ correct = (2..3).collect{|i| "/etc/rc#{i}.d/S99script"}
42
+ assert_equal correct, @solaris.init_links('/path/to/init/script', {:init => {}})
43
+ end
44
+ def test_available_native_packages
45
+ assert_equal(
46
+ [
47
+ {:metadata=>
48
+ {:name=>'CSWcurl', :version => '7.25.0', :package_version => '2012.04.26'},
49
+ :source=>:native_installed,
50
+ :prefer=>true},
51
+ {:metadata=>
52
+ {:name=>'CSWcurl', :version => '7.25.0', :package_version => '2012.04.26'},
53
+ :source=>:native_available},
54
+ ],
55
+ @solaris.available_native_packages('CSWcurl'))
56
+ assert_equal(
57
+ [
58
+ {:metadata=>
59
+ {:name=>'CSWwget', :version=>'1.13.4', :package_version=>'2012.05.12'},
60
+ :source=>:native_available},
61
+ ],
62
+ @solaris.available_native_packages('CSWwget'))
63
+ assert_equal(
64
+ [
65
+ {:metadata=>
66
+ {:name=>'SUNWzfsu', :version=>'11.10.0', :package_version=>'2006.05.18.01.46'},
67
+ :source=>:native_installed,
68
+ :prefer=>true},
69
+ ],
70
+ @solaris.available_native_packages('SUNWzfsu'))
71
+ assert_equal [], @solaris.available_native_packages('bogus')
72
+ end
73
+ def test_native_pkg_to_install_string
74
+ assert_equal 'pkg-1.0,REV=1', @solaris.native_pkg_to_install_string({:metadata => {:name => 'pkg', :version => '1.0', :package_version => '1'}})
75
+ assert_equal 'pkg-1.0', @solaris.native_pkg_to_install_string({:metadata => {:name => 'pkg', :version => '1.0'}})
76
+ end
77
+ def test_install_native_package
78
+ @solaris.expects(:system).with("#{@pkgutil} -y -i CSWcurl-7.25.0,REV=2012.04.26")
79
+ @solaris.install_native_package({:metadata => {:name => 'CSWcurl', :version => '7.25.0', :package_version => '2012.04.26'}})
80
+ end
81
+ def test_upgrade_native_package
82
+ @solaris.expects(:system).with("#{@pkgutil} -y -u CSWcurl-7.25.0,REV=2012.04.26")
83
+ @solaris.upgrade_native_package({:metadata => {:name => 'CSWcurl', :version => '7.25.0', :package_version => '2012.04.26'}})
84
+ end
85
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # Tests Windows OS abstraction code
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ class TpkgOSWindowsTests < Test::Unit::TestCase
8
+ include TpkgTests
9
+
10
+ def setup
11
+ @windows = Tpkg::OS::Windows.new
12
+ end
13
+
14
+ def test_supported
15
+ fact = Facter::Util::Fact.new('operatingsystem')
16
+ Facter.expects(:[]).with('operatingsystem').returns(fact).at_least_once
17
+ fact.stubs(:value).returns('windows')
18
+ assert Tpkg::OS::Windows.supported?
19
+ fact.stubs(:value).returns('Other')
20
+ refute Tpkg::OS::Windows.supported?
21
+ end
22
+
23
+ def test_sudo_default
24
+ refute @windows.sudo_default?
25
+ end
26
+ end
@@ -0,0 +1,134 @@
1
+
2
+
3
+ #
4
+ # Test tpkg's query features
5
+ #
6
+
7
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
8
+
9
+ class TpkgQueryTests < Test::Unit::TestCase
10
+ include TpkgTests
11
+
12
+ def setup
13
+ Tpkg::set_prompt(false)
14
+
15
+ # temp dir that will automatically get deleted at end of test run, can be
16
+ # used for storing packages
17
+ @tempoutdir = Dir.mktmpdir('tempoutdir')
18
+
19
+ # Make up our regular test package
20
+ @pkgfile = make_package(:output_directory => @tempoutdir)
21
+ end
22
+
23
+ def test_metadata_for_installed_packages
24
+ Dir.mktmpdir('testbase') do |testbase|
25
+ apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
26
+ tpkg = Tpkg.new(:base => testbase, :sources => [apkg])
27
+ tpkg.install(['a'], PASSPHRASE)
28
+ metadata = tpkg.metadata_for_installed_packages
29
+ assert_equal(1, metadata.length)
30
+ assert_equal('a', metadata.first[:name])
31
+ FileUtils.rm_f(apkg)
32
+ end
33
+ end
34
+
35
+ def test_installed_packages
36
+ Dir.mktmpdir('testbase') do |testbase|
37
+ apkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
38
+ bpkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'b', 'version' => '2.0' }, :remove => ['operatingsystem', 'architecture'])
39
+ tpkg = Tpkg.new(:base => testbase, :sources => [apkg, bpkg])
40
+ tpkg.install(['a', 'b'], PASSPHRASE)
41
+
42
+ instpkgs = tpkg.installed_packages
43
+ assert_equal(2, instpkgs.length)
44
+ assert(instpkgs.any? {|instpkg| instpkg[:metadata][:name] == 'a'})
45
+ assert(instpkgs.any? {|instpkg| instpkg[:metadata][:name] == 'b'})
46
+ assert(instpkgs.all? {|instpkg| instpkg[:source] == :currently_installed})
47
+ assert(instpkgs.all? {|instpkg| instpkg[:prefer] == true})
48
+
49
+ instpkgs = tpkg.installed_packages('b')
50
+ assert_equal(1, instpkgs.length)
51
+ assert_equal('b', instpkgs.first[:metadata][:name])
52
+
53
+ FileUtils.rm_f(apkg)
54
+ FileUtils.rm_f(bpkg)
55
+ end
56
+ end
57
+
58
+ def test_installed_packages_that_meet_requirement
59
+ Dir.mktmpdir('testbase') do |testbase|
60
+ tpkg = Tpkg.new(:base => testbase)
61
+ pkgfiles = []
62
+ ['1.0', '2.0'].each do |ver|
63
+ Dir.mktmpdir('srcdir') do |srcdir|
64
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
65
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a', 'version' => ver }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
66
+ tpkg.install([pkg], PASSPHRASE)
67
+ pkgfiles << pkg
68
+ end
69
+ end
70
+ result = tpkg.installed_packages_that_meet_requirement
71
+ assert_equal(2, result.length)
72
+ result = tpkg.installed_packages_that_meet_requirement({:name => 'a'})
73
+ assert_equal(2, result.length)
74
+ result = tpkg.installed_packages_that_meet_requirement({:name => 'a', :minimum_version => '2.0'})
75
+ assert_equal(1, result.length)
76
+ pkgfiles.each { |pkg| FileUtils.rm_f(pkg) }
77
+ end
78
+ end
79
+
80
+ def test_files_for_installed_packages
81
+ pkgfiles = []
82
+ # Make up a couple of packages with different files in them so that
83
+ # they don't conflict
84
+ ['a', 'b'].each do |pkgname|
85
+ Dir.mktmpdir('srcdir') do |srcdir|
86
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
87
+ FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'directory'))
88
+ File.open(File.join(srcdir, 'reloc', 'directory', pkgname), 'w') do |file|
89
+ file.puts pkgname
90
+ end
91
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => {'name' => pkgname}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
92
+ end
93
+ end
94
+
95
+ Dir.mktmpdir('testbase') do |testbase|
96
+ tpkg = Tpkg.new(:base => testbase, :sources => pkgfiles)
97
+ tpkg.install(['a', 'b'], PASSPHRASE)
98
+
99
+ files = tpkg.files_for_installed_packages
100
+ assert_equal(2, files.length)
101
+ files.each do |pkgfile, fip|
102
+ assert_equal(0, fip[:root].length) # Neither package has non-relocatable files
103
+ assert_equal(2, fip[:reloc].length) # Each package has two relocatable files (a directory and a file)
104
+ pkgname = fip[:metadata][:name]
105
+ assert_equal(File.join('directory', ''), fip[:reloc].first)
106
+ assert_equal(File.join('directory', pkgname), fip[:reloc].last)
107
+ assert_equal(File.join(testbase, 'directory', ''), fip[:normalized].first)
108
+ assert_equal(File.join(testbase, 'directory', pkgname), fip[:normalized].last)
109
+ end
110
+
111
+ files = tpkg.files_for_installed_packages(pkgfiles.first)
112
+ assert_equal(1, files.length)
113
+ end
114
+
115
+ pkgfiles.each { |pkg| FileUtils.rm_f(pkg) }
116
+ end
117
+
118
+ def test_files_in_package
119
+ files = Tpkg::files_in_package(@pkgfile)
120
+ assert_equal(0, files[:root].length)
121
+ pwd = Dir.pwd
122
+ Dir.chdir(File.join(TESTPKGDIR, 'reloc'))
123
+ reloc_expected = Dir.glob('*')
124
+ Dir.chdir(pwd)
125
+ assert_equal(reloc_expected.length, files[:reloc].length)
126
+ reloc_expected.each { |r| assert(files[:reloc].include?(r)) }
127
+ files[:reloc].each { |r| assert(reloc_expected.include?(r)) }
128
+ end
129
+
130
+ def teardown
131
+ FileUtils.rm_rf(@tempoutdir)
132
+ end
133
+ end
134
+
@@ -0,0 +1,539 @@
1
+ #
2
+ # Test tpkg's ability to remove packages
3
+ #
4
+
5
+ require File.expand_path('tpkgtest', File.dirname(__FILE__))
6
+
7
+ class TpkgRemoveTests < Test::Unit::TestCase
8
+ include TpkgTests
9
+
10
+ def setup
11
+ Tpkg::set_prompt(false)
12
+
13
+ # temp dir that will automatically get deleted at end of test run, can be
14
+ # used for storing packages
15
+ @tempoutdir = Dir.mktmpdir('tempoutdir')
16
+
17
+ # Pretend to be an OS with init script support
18
+ fact = Facter::Util::Fact.new('operatingsystem')
19
+ fact.stubs(:value).returns('RedHat')
20
+ Facter.stubs(:[]).returns(fact)
21
+ end
22
+
23
+ def test_remove_dep
24
+ # b and c depends on a
25
+ # d depends on b
26
+ pkgfiles = []
27
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a' }, :remove => ['operatingsystem', 'architecture'])
28
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'b' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'a' => {}})
29
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'c' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'a' => {}})
30
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'b' => {}})
31
+ Dir.mktmpdir('testbase') do |testbase|
32
+ tpkg = Tpkg.new(:base => testbase, :sources => pkgfiles)
33
+ assert_nothing_raised { tpkg.install(pkgfiles, PASSPHRASE) }
34
+
35
+ # a, b, c and d are installed
36
+ metadata = tpkg.metadata_for_installed_packages
37
+ assert_equal(4, metadata.length)
38
+
39
+ # removing a with :remove_all_dep option should remove b, c and d as well
40
+ assert_nothing_raised { tpkg.remove(['a'], {:remove_all_dep => true})}
41
+ metadata = tpkg.metadata_for_installed_packages
42
+ assert_equal(0, metadata.length)
43
+ end
44
+ end
45
+
46
+ def test_remove_prereq
47
+ # e requires c
48
+ # d requires c and b
49
+ # c requires a
50
+ pkgfiles = []
51
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'a' }, :remove => ['operatingsystem', 'architecture'])
52
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'b' }, :remove => ['operatingsystem', 'architecture'])
53
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'c' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'a' => {}})
54
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'd' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'c' => {}, 'b' => {}})
55
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => { 'name' => 'e' }, :remove => ['operatingsystem', 'architecture'], :dependencies => {'c' => {}})
56
+ Dir.mktmpdir('testbase') do |testbase|
57
+ tpkg = Tpkg.new(:base => testbase, :sources => pkgfiles)
58
+ assert_nothing_raised { tpkg.install(pkgfiles, PASSPHRASE) }
59
+
60
+ # a, b, c, d and e are installed
61
+ metadata = tpkg.metadata_for_installed_packages
62
+ assert_equal(5, metadata.length)
63
+
64
+ # removing d with :remove_all_prereq option should remove d and b only and not c and a because
65
+ # e still depends on c
66
+ assert_nothing_raised { tpkg.remove(['d'], {:remove_all_prereq => true})}
67
+ metadata = tpkg.metadata_for_installed_packages
68
+ assert_equal(3, metadata.length)
69
+ end
70
+ end
71
+
72
+ def test_remove
73
+ pkgfiles = []
74
+ # Make up a couple of packages with different files in them so that
75
+ # they don't conflict
76
+ ['a', 'b'].each do |pkgname|
77
+ Dir.mktmpdir('srcdir') do |srcdir|
78
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
79
+ FileUtils.mkdir_p(File.join(srcdir, 'reloc', 'directory'))
80
+ File.open(File.join(srcdir, 'reloc', 'directory', pkgname), 'w') do |file|
81
+ file.puts pkgname
82
+ end
83
+ File.open(File.join(srcdir, 'reloc', 'directory', "#{pkgname}.conf"), 'w') do |file|
84
+ file.puts pkgname
85
+ end
86
+ pkgfiles << make_package(:output_directory => @tempoutdir, :change => {'name' => pkgname}, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'], :files => { "directory/#{pkgname}.conf" => { 'config' => true}})
87
+ end
88
+ end
89
+
90
+ Dir.mktmpdir('testroot') do |testroot|
91
+ testbase = File.join(testroot, 'home', 'tpkg')
92
+ FileUtils.mkdir_p(testbase)
93
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
94
+
95
+ tpkg.install(['a', 'b'], PASSPHRASE)
96
+
97
+ assert_nothing_raised { tpkg.remove(['a']) }
98
+
99
+ assert(!File.exist?(File.join(testbase, 'directory', 'a')))
100
+ assert(File.exist?(File.join(testbase, 'directory', 'b')))
101
+
102
+ assert_nothing_raised { tpkg.remove(['b']) }
103
+
104
+ assert(!File.exist?(File.join(testbase, 'directory', 'b')))
105
+ assert(!File.exist?(File.join(testbase, 'directory')))
106
+ assert(File.exist?(File.join(testbase)))
107
+
108
+ # Test that we can use package filename for remove
109
+ tpkg.install(['a', 'b'], PASSPHRASE)
110
+ filenames = pkgfiles.collect{ |pkgfile| File.basename(pkgfile)}
111
+ assert_nothing_raised { tpkg.remove(filenames) }
112
+ assert(!File.exist?(File.join(testbase, 'directory', 'a')))
113
+ assert(!File.exist?(File.join(testbase, 'directory', 'b')))
114
+ assert(!File.exist?(File.join(testbase, 'directory')))
115
+ assert(File.exist?(File.join(testbase)))
116
+
117
+ # Remove a file manually. tpkg.remove should warn that the file
118
+ # is missing but not abort.
119
+ tpkg.install(['a'], PASSPHRASE)
120
+ File.delete(File.join(testbase, 'directory', 'a'))
121
+ puts "Missing file warning expected here:"
122
+ assert_nothing_raised { tpkg.remove(['a']) }
123
+
124
+ # Insert another file into the directory. tpkg.remove should warn
125
+ # that the directory isn't empty but not abort.
126
+ tpkg.install(['a'], PASSPHRASE)
127
+ File.open(File.join(testbase, 'directory', 'anotherfile'), 'w') do |file|
128
+ file.puts 'junk'
129
+ end
130
+ assert_nothing_raised { tpkg.remove(['a']) }
131
+
132
+ # Test removing all packages by passing no arguments to remove
133
+ tpkg.install(['a', 'b'], PASSPHRASE)
134
+ assert_nothing_raised { tpkg.remove }
135
+ assert(!File.exist?(File.join(testbase, 'directory', 'a')))
136
+ assert(!File.exist?(File.join(testbase, 'directory', 'b')))
137
+
138
+ # Test removing config files
139
+ # If config file has been modified, then tpkg should not remove it
140
+ tpkg.install(['a', 'b'], PASSPHRASE)
141
+ File.open(File.join(testbase, 'directory', "a.conf"), 'w') do |file|
142
+ file.puts "Modified"
143
+ end
144
+ assert_nothing_raised { tpkg.remove }
145
+ assert(File.exist?(File.join(testbase, 'directory', 'a.conf')))
146
+ assert(!File.exist?(File.join(testbase, 'directory', 'b.conf')))
147
+ end
148
+
149
+ # Clean up
150
+ pkgfiles.each { |pkgfile| FileUtils.rm_f(pkgfile) }
151
+
152
+ # Test that preremove/postremove are run at the right points
153
+ # Make up a package with scripts that create files so we can check timestamps
154
+ # Also, test tpkg should chdir to package unpack directory before calling
155
+ # pre/post/install/remove scripts
156
+ scriptfiles = {}
157
+ pkgfile = nil
158
+
159
+ Dir.mktmpdir('srcdir') do |srcdir|
160
+ # Include the stock test package contents
161
+ system("#{Tpkg::find_tar} -C #{TESTPKGDIR} --exclude .svn -cf - . | #{Tpkg::find_tar} -C #{srcdir} -xf -")
162
+
163
+ # Add some dummy file for testing relative path
164
+ File.open(File.join(srcdir, "dummyfile"), 'w') do |file|
165
+ file.puts("hello world")
166
+ end
167
+
168
+ # Then add scripts
169
+ ['preremove', 'postremove'].each do |script|
170
+ File.open(File.join(srcdir, script), 'w') do |scriptfile|
171
+ # We have each script write to a temporary file (so that we can
172
+ # check the timestamp of that file to ensure proper ordering) and
173
+ # print out the name of the file (just to aid debugging)
174
+ tmpfile = Tempfile.new('tpkgtest_script')
175
+ scriptfiles[script] = tmpfile
176
+ scriptfile.puts('#!/bin/sh')
177
+ # Test that tpkg set $TPKG_HOME before running the script
178
+ scriptfile.puts('echo TPKG_HOME: \"$TPKG_HOME\"')
179
+ # Test that we had chdir'ed to package unpack directory
180
+ scriptfile.puts('ls dummyfile || exit 1')
181
+ scriptfile.puts('test -n "$TPKG_HOME" || exit 1')
182
+ scriptfile.puts("echo #{script} > #{tmpfile.path}")
183
+ scriptfile.puts("echo #{script}: #{tmpfile.path}")
184
+ scriptfile.puts('sleep 1')
185
+ end
186
+ File.chmod(0755, File.join(srcdir, script))
187
+ end
188
+ # Change name of package so that the file doesn't conflict with @pkgfile
189
+ pkgfile = make_package(:output_directory => @tempoutdir, :source_directory => srcdir, :change => {'name' => 'scriptpkg'}, :remove => ['operatingsystem', 'architecture'])
190
+ end
191
+
192
+ # Install the script package
193
+ Dir.mktmpdir('testroot') do |testroot|
194
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkgfile])
195
+ assert_nothing_raised { tpkg.install([pkgfile], PASSPHRASE) }
196
+ assert_nothing_raised { tpkg.remove(['scriptpkg']) }
197
+ # FIXME: Need a way to test that the package remove occurred between the two scripts
198
+ assert(File.stat(scriptfiles['preremove'].path).mtime < File.stat(scriptfiles['postremove'].path).mtime)
199
+ end
200
+
201
+ # Test init script handling
202
+ pkg = nil
203
+ pkg2 = nil
204
+ Dir.mktmpdir('srcdir') do |srcdir|
205
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
206
+ FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
207
+ File.open(File.join(srcdir, 'reloc', 'myinit'), 'w') do |file|
208
+ file.puts('init script')
209
+ end
210
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg' }, :source_directory => srcdir, :files => { 'myinit' => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
211
+ pkg2 = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg2' }, :source_directory => srcdir, :files => { 'myinit' => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
212
+ end
213
+ Dir.mktmpdir('testroot') do |testroot|
214
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg,pkg2])
215
+ tpkg2 = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg2'), :sources => [pkg,pkg2])
216
+ metadata = Tpkg::metadata_from_package(pkg)
217
+ metadata2 = Tpkg::metadata_from_package(pkg2)
218
+ tpkg.install([pkg], PASSPHRASE)
219
+ tpkg2.install([pkg2], PASSPHRASE)
220
+ tpkg.remove(['initpkg'])
221
+ tpkg.init_links(metadata).each do |link, init_script|
222
+ assert(!File.exist?(link) && !File.symlink?(link))
223
+ end
224
+ # Test the handling of packages with conflicting init scripts.
225
+ # The link should end up named with a '1' at the end.
226
+ # Make sure it is still there after the removal of 'initpkg'
227
+ tpkg2.init_links(metadata2).each do |link, init_script|
228
+ assert(File.symlink?(link + '1'))
229
+ assert_equal(init_script, File.readlink(link + '1'))
230
+ end
231
+ # Now remove 'initpkg2' and verify that it is gone
232
+ tpkg2.remove(['initpkg2'])
233
+ tpkg2.init_links(metadata2).each do |link, init_script|
234
+ assert(!File.exist?(link + '1') && !File.symlink?(link + '1'))
235
+ end
236
+ end
237
+
238
+ # Test external handling
239
+ extname = 'testext'
240
+ extdata = "This is a test of an external hook\nwith multiple lines\nof data"
241
+ pkg = nil
242
+ Dir.mktmpdir('srcdir') do |srcdir|
243
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
244
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'externalpkg' }, :externals => { extname => { 'data' => extdata } }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
245
+ end
246
+ Dir.mktmpdir('testroot') do |testroot|
247
+ externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
248
+ FileUtils.mkdir_p(externalsdir)
249
+ # Create an external script which puts the data into a file named after
250
+ # the package, and removes any files named after the package on removal.
251
+ Dir.mktmpdir('externaltest') do |externaltestdir|
252
+ extscript = File.join(externalsdir, extname)
253
+ File.open(extscript, 'w') do |file|
254
+ file.puts <<EOF
255
+ #!/bin/sh
256
+ set -e
257
+
258
+ pkgfile=$1
259
+ operation=$2
260
+
261
+ requestfile=#{externaltestdir}/$pkgfile
262
+
263
+ case "$operation" in
264
+ 'install')
265
+ mkdir -p `dirname "$requestfile"`
266
+ tmpfile=`mktemp "$requestfile.XXXXXX"` || exit 1
267
+ # Dump in the data passed to us on stdin
268
+ cat >> $tmpfile
269
+ ;;
270
+ 'remove')
271
+ rm -f "$requestfile".*
272
+ # Avoid generating SIGPIPE in tpkg
273
+ cat > /dev/null
274
+ ;;
275
+ *)
276
+ echo "$0: Invalid arguments"
277
+ exit 1
278
+ ;;
279
+ esac
280
+ EOF
281
+ end
282
+ File.chmod(0755, extscript)
283
+ # And run the test
284
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
285
+ tpkg.install([pkg], PASSPHRASE)
286
+ assert(Dir.entries(externaltestdir).length > 2)
287
+ assert_nothing_raised { tpkg.remove(['externalpkg']) }
288
+ # . and ..
289
+ assert_equal(2, Dir.entries(externaltestdir).length)
290
+ end
291
+ end
292
+
293
+ # Test handling of external with datafile
294
+ # The datafile is only read at install, not at remove, so this really
295
+ # doesn't test a unique code path. Rather it just serves to verify that
296
+ # nothing breaks on removal in the face of a datafile being defined.
297
+ extname = 'testext'
298
+ extdata = "This is a test of an external hook\nwith multiple lines\nof data from a datafile"
299
+ pkg = nil
300
+ Dir.mktmpdir('srcdir') do |srcdir|
301
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
302
+ # Create the datafile
303
+ File.open(File.join(srcdir, 'datafile'), 'w') do |file|
304
+ file.print(extdata)
305
+ end
306
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'externalpkg' }, :externals => { extname => { 'datafile' => './datafile' } }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
307
+ end
308
+ Dir.mktmpdir('testroot') do |testroot|
309
+ externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
310
+ FileUtils.mkdir_p(externalsdir)
311
+ # Create an external script which puts the data into a file named after
312
+ # the package, and removes any files named after the package on removal.
313
+ Dir.mktmpdir('externaltest') do |externaltestdir|
314
+ extscript = File.join(externalsdir, extname)
315
+ File.open(extscript, 'w') do |file|
316
+ file.puts <<EOF
317
+ #!/bin/sh
318
+ set -e
319
+
320
+ pkgfile=$1
321
+ operation=$2
322
+
323
+ requestfile=#{externaltestdir}/$pkgfile
324
+
325
+ case "$operation" in
326
+ 'install')
327
+ mkdir -p `dirname "$requestfile"`
328
+ tmpfile=`mktemp "$requestfile.XXXXXX"` || exit 1
329
+ # Dump in the data passed to us on stdin
330
+ cat >> $tmpfile
331
+ ;;
332
+ 'remove')
333
+ rm -f "$requestfile".*
334
+ # Avoid generating SIGPIPE in tpkg
335
+ cat > /dev/null
336
+ ;;
337
+ *)
338
+ echo "$0: Invalid arguments"
339
+ exit 1
340
+ ;;
341
+ esac
342
+ EOF
343
+ end
344
+ File.chmod(0755, extscript)
345
+ # And run the test
346
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
347
+ tpkg.install([pkg], PASSPHRASE)
348
+ assert(Dir.entries(externaltestdir).length > 2)
349
+ assert_nothing_raised { tpkg.remove(['externalpkg']) }
350
+ # . and ..
351
+ assert_equal(2, Dir.entries(externaltestdir).length)
352
+ end
353
+ end
354
+
355
+ # Test handling of external with datascript
356
+ # The datascript is only run at install, not at remove, so this really
357
+ # doesn't test a unique code path. Rather it just serves to verify that
358
+ # nothing breaks on removal in the face of a datascript being defined.
359
+ extname = 'testext'
360
+ extdata = "This is a test of an external hook\nwith multiple lines\nof data from a datascript"
361
+ pkg = nil
362
+ Dir.mktmpdir('srcdir') do |srcdir|
363
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
364
+ # Create the datascript
365
+ File.open(File.join(srcdir, 'datascript'), 'w') do |file|
366
+ file.puts('#!/bin/sh')
367
+ # echo may or may not add a trailing \n depending on which echo we end
368
+ # up, so use printf, which doesn't add things.
369
+ file.puts("printf \"#{extdata}\"")
370
+ end
371
+ File.chmod(0755, File.join(srcdir, 'datascript'))
372
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'externalpkg' }, :externals => { extname => { 'datascript' => './datascript' } }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
373
+ end
374
+ Dir.mktmpdir('testroot') do |testroot|
375
+ externalsdir = File.join(testroot, 'usr', 'lib', 'tpkg', 'externals')
376
+ FileUtils.mkdir_p(externalsdir)
377
+ # Create an external script which puts the data into a file named after
378
+ # the package, and removes any files named after the package on removal.
379
+ Dir.mktmpdir('externaltest') do |externaltestdir|
380
+ extscript = File.join(externalsdir, extname)
381
+ File.open(extscript, 'w') do |file|
382
+ file.puts <<EOF
383
+ #!/bin/sh
384
+ set -e
385
+
386
+ pkgfile=$1
387
+ operation=$2
388
+
389
+ requestfile=#{externaltestdir}/$pkgfile
390
+
391
+ case "$operation" in
392
+ 'install')
393
+ mkdir -p `dirname "$requestfile"`
394
+ tmpfile=`mktemp "$requestfile.XXXXXX"` || exit 1
395
+ # Dump in the data passed to us on stdin
396
+ cat >> $tmpfile
397
+ ;;
398
+ 'remove')
399
+ rm -f "$requestfile".*
400
+ # Avoid generating SIGPIPE in tpkg
401
+ cat > /dev/null
402
+ ;;
403
+ *)
404
+ echo "$0: Invalid arguments"
405
+ exit 1
406
+ ;;
407
+ esac
408
+ EOF
409
+ end
410
+ File.chmod(0755, extscript)
411
+ # And run the test
412
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
413
+ tpkg.install([pkg], PASSPHRASE)
414
+ assert(Dir.entries(externaltestdir).length > 2)
415
+ assert_nothing_raised { tpkg.remove(['externalpkg']) }
416
+ # . and ..
417
+ assert_equal(2, Dir.entries(externaltestdir).length)
418
+ end
419
+ end
420
+ end
421
+
422
+ def test_remove_init_scripts
423
+ metadata = nil
424
+ Dir.mktmpdir('srcdir') do |srcdir|
425
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
426
+ create_metadata_file(File.join(srcdir, 'tpkg.xml'), :change => { 'name' => 'initpkg' }, :files => { 'etc/init.d/initscript' => { 'init' => {} } })
427
+ metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
428
+ end
429
+
430
+ Dir.mktmpdir('testroot') do |testroot|
431
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'))
432
+
433
+ link = nil
434
+ init_script = nil
435
+ tpkg.init_links(metadata).each do |l, is|
436
+ link = l
437
+ init_script = is
438
+ end
439
+
440
+ # init_links returns an empty list on platforms where tpkg doesn't have
441
+ # init script support
442
+ if link
443
+ # Standard symlink using the base name is removed
444
+ FileUtils.mkdir_p(File.dirname(link))
445
+ File.symlink(init_script, link)
446
+ tpkg.remove_init_scripts(metadata)
447
+ assert(!File.exist?(link) && !File.symlink?(link))
448
+
449
+ # Links with suffixes from 1..9 are removed
450
+ 1.upto(9) do |i|
451
+ FileUtils.rm(Dir.glob(link + '*'))
452
+ File.symlink(init_script, link + i.to_s)
453
+ File.symlink(init_script, link + '1') if (i != 1)
454
+ 2.upto(i-1) do |j|
455
+ File.symlink('somethingelse', link + j.to_s)
456
+ end
457
+ tpkg.remove_init_scripts(metadata)
458
+ assert(!File.exist?(link) && !File.symlink?(link))
459
+ assert(!File.exist?(link + '1') && !File.symlink?(link + '1'))
460
+ 2.upto(i-1) do |j|
461
+ assert(File.symlink?(link + j.to_s))
462
+ assert_equal('somethingelse', File.readlink(link + j.to_s))
463
+ end
464
+ end
465
+
466
+ # Links with suffixes of 0 or 10 are left alone
467
+ File.symlink(init_script, link + '0')
468
+ File.symlink(init_script, link + '10')
469
+ tpkg.remove_init_scripts(metadata)
470
+ assert(File.symlink?(link + '0'))
471
+ assert_equal(init_script, File.readlink(link + '0'))
472
+ assert(File.symlink?(link + '10'))
473
+ assert_equal(init_script, File.readlink(link + '10'))
474
+
475
+ # Running as non-root, permissions issues prevent link removal, warning
476
+ FileUtils.rm(Dir.glob(link + '*'))
477
+ File.symlink(init_script, link)
478
+ File.chmod(0000, File.dirname(link))
479
+ assert_nothing_raised { tpkg.remove_init_scripts(metadata) }
480
+ # FIXME: look for warning in stderr
481
+ File.chmod(0755, File.dirname(link))
482
+ assert(File.symlink?(link))
483
+ assert_equal(init_script, File.readlink(link))
484
+ end
485
+ end
486
+ end
487
+
488
+ # Test that the remove method calls remove_crontabs as appropriate
489
+ def test_remove_remove_crontabs
490
+ # FIXME
491
+ end
492
+
493
+ def test_skip_remove_stop
494
+ # Make a test package with an init script
495
+ pkg = nil
496
+ tmpfile = Tempfile.new('tpkgtest_script')
497
+ Dir.mktmpdir('srcdir') do |srcdir|
498
+ FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
499
+ FileUtils.mkdir_p(File.join(srcdir, 'reloc'))
500
+ initscript = File.join(srcdir, 'reloc', 'myinit')
501
+ File.open(initscript, 'w') do |file|
502
+ file.puts('#!/bin/sh')
503
+ file.puts('case "$1" in')
504
+ file.puts("'stop')")
505
+ file.puts(" echo 'test_skip_remove_stop' > #{tmpfile.path}")
506
+ file.puts(' ;;')
507
+ file.puts('esac')
508
+ end
509
+ File.chmod(0755, initscript)
510
+ pkg = make_package(:output_directory => @tempoutdir, :change => { 'name' => 'initpkg' }, :source_directory => srcdir, :files => { 'myinit' => { 'init' => {} } }, :remove => ['operatingsystem', 'architecture'])
511
+ end
512
+
513
+ # Removing the package without skip_remove_stop should run the init script
514
+ # with a "stop" argument on package removal
515
+ Dir.mktmpdir('testroot') do |testroot|
516
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
517
+ tpkg.install([pkg], PASSPHRASE)
518
+ tpkg.remove(['initpkg'])
519
+ assert_equal("test_skip_remove_stop\n", File.read(tmpfile.path))
520
+ end
521
+
522
+ # Clear out the temp file to reset
523
+ File.open(tmpfile.path, 'w') {}
524
+
525
+ # Removing the package with skip_remove_stop should not run the init
526
+ # script on package removal
527
+ Dir.mktmpdir('testroot') do |testroot|
528
+ tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [pkg])
529
+ tpkg.install([pkg], PASSPHRASE)
530
+ tpkg.remove(['initpkg'], :skip_remove_stop => true)
531
+ assert_equal("", File.read(tmpfile.path))
532
+ end
533
+ end
534
+
535
+ def teardown
536
+ FileUtils.rm_rf(@tempoutdir)
537
+ end
538
+ end
539
+