tpkg 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/Portfile +39 -0
- data/Portfile.template +39 -0
- data/README.md +43 -0
- data/Rakefile +468 -18
- data/bin/gem2tpkg +2 -2
- data/bin/tpkg +18 -13
- data/bin/tpkg_uploader +132 -0
- data/ca.pem +1 -0
- data/control +7 -0
- data/depend +3 -0
- data/externals-etch/authorized_keys +40 -0
- data/externals-etch/group +9 -0
- data/externals-etch/iptables +38 -0
- data/externals-etch/limits +30 -0
- data/externals-etch/nfs +30 -0
- data/externals-etch/sudo +30 -0
- data/externals-etch/supplemental_groups +8 -0
- data/externals-etch/sysctl +30 -0
- data/externals-etch/user +41 -0
- data/externals/group +39 -0
- data/externals/supplemental_groups +48 -0
- data/externals/user +39 -0
- data/lib/tpkg.rb +260 -991
- data/lib/tpkg/os.rb +164 -0
- data/lib/tpkg/os/debian.rb +159 -0
- data/lib/tpkg/os/freebsd.rb +113 -0
- data/lib/tpkg/os/macosx.rb +113 -0
- data/lib/tpkg/os/redhat.rb +173 -0
- data/lib/tpkg/os/solaris.rb +101 -0
- data/lib/tpkg/os/windows.rb +26 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
- data/lib/tpkg/version.rb +3 -0
- data/man/man1/cpan2tpkg.1 +82 -0
- data/man/man1/gem2tpkg.1 +120 -0
- data/man/man1/tpkg.1 +411 -0
- data/pkginfo +8 -0
- data/postinstall.solaris +11 -0
- data/postremove.solaris +16 -0
- data/schema/schema-1.0.5.yml +0 -0
- data/schema/schema-1.0.6.yml +0 -0
- data/schema/schema-1.0.7.yml +0 -0
- data/schema/schema-1.0.8.yml +0 -0
- data/schema/schema-1.0.9.yml +0 -0
- data/schema/schema.yml +0 -0
- data/schema/tpkg-1.0.0.dtd +0 -0
- data/schema/tpkg-1.0.1.dtd +0 -0
- data/schema/tpkg-1.0.2.dtd +0 -0
- data/schema/tpkg-1.0.3.dtd +0 -0
- data/schema/tpkg-1.0.4.dtd +0 -0
- data/schema/tpkg-1.0.5.dtd +0 -0
- data/schema/tpkg-1.0.6.dtd +0 -0
- data/schema/tpkg-1.0.7.dtd +0 -0
- data/schema/tpkg-1.0.8.dtd +0 -0
- data/schema/tpkg-1.0.9.dtd +0 -0
- data/schema/tpkg.dtd +0 -0
- data/test/TODO +30 -0
- data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
- data/test/test_checksum.rb +53 -0
- data/test/test_compress.rb +55 -0
- data/test/test_conflict.rb +41 -0
- data/test/test_crontabs.rb +398 -0
- data/test/test_dependency.rb +1113 -0
- data/test/test_downgrade.rb +80 -0
- data/test/test_download.rb +95 -0
- data/test/test_encrypt.rb +136 -0
- data/test/test_filemetadata.rb +131 -0
- data/test/test_initscript.rb +93 -0
- data/test/test_install.rb +186 -0
- data/test/test_lock.rb +82 -0
- data/test/test_make.rb +410 -0
- data/test/test_metadata.rb +805 -0
- data/test/test_misc.rb +379 -0
- data/test/test_options.rb +1711 -0
- data/test/test_os.rb +193 -0
- data/test/test_os_debian.rb +99 -0
- data/test/test_os_freebsd.rb +89 -0
- data/test/test_os_macosx.rb +79 -0
- data/test/test_os_redhat.rb +124 -0
- data/test/test_os_solaris.rb +85 -0
- data/test/test_os_windows.rb +26 -0
- data/test/test_query.rb +134 -0
- data/test/test_remove.rb +539 -0
- data/test/test_tar.rb +99 -0
- data/test/test_unpack.rb +977 -0
- data/test/test_upgrade.rb +398 -0
- data/test/test_version.rb +54 -0
- data/test/testcmds/crontab +14 -0
- data/test/testcmds/debian/apt-cache +145 -0
- data/test/testcmds/debian/dpkg-query +16 -0
- data/test/testcmds/freebsd/pkg_info +13 -0
- data/test/testcmds/macosx/port +35 -0
- data/test/testcmds/redhat/rpmbuild +6 -0
- data/test/testcmds/redhat/yum +90 -0
- data/test/testcmds/solaris/pkginfo +25 -0
- data/test/testcmds/solaris/pkgutil +36 -0
- data/test/testpkg/reloc/encfile +2 -0
- data/test/testpkg/reloc/file +2 -0
- data/test/testpkg/reloc/precryptfile +1 -0
- data/test/testpkg/reloc/precryptfile.plaintext +3 -0
- data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-default-perms.xml +28 -0
- data/test/testpkg/tpkg-default-perms.yml +20 -0
- data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-nativedeps.yml +13 -0
- data/test/testpkg/tpkg-nofiles.xml +14 -0
- data/test/testpkg/tpkg-nofiles.yml +9 -0
- data/test/testpkg/tpkg.xml +35 -0
- data/test/testpkg/tpkg.yml +25 -0
- data/test/tpkgtest.rb +300 -0
- data/tpkg.conf +16 -0
- data/tpkg.gemspec +24 -0
- data/tpkg.spec +28 -0
- data/tpkg.xml +17 -0
- data/tpkg_profile.sh +32 -0
- metadata +306 -31
data/pkginfo
ADDED
data/postinstall.solaris
ADDED
data/postremove.solaris
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# Remove the hook from /etc/profile
|
4
|
+
start_line=`grep -n "BEGIN TPKG" /etc/profile | awk -F: '{print $1}'`
|
5
|
+
end_line=`grep -n "END TPKG" /etc/profile | awk -F: '{print $1}'`
|
6
|
+
# Check that we actually got valid start and end line
|
7
|
+
if [ $start_line ] && [ $end_line ] && [ $start_line -lt $end_line ]
|
8
|
+
then
|
9
|
+
tmpfile=`mktemp -t etc.profile.XXXXXX`
|
10
|
+
# yank out those lines
|
11
|
+
sed -e "$start_line,$end_line d" /etc/profile > $tmpfile
|
12
|
+
chmod 644 $tmpfile
|
13
|
+
if [ -s $tmpfile ]; then
|
14
|
+
mv $tmpfile /etc/profile
|
15
|
+
fi
|
16
|
+
fi
|
data/schema/schema-1.0.5.yml
CHANGED
File without changes
|
data/schema/schema-1.0.6.yml
CHANGED
File without changes
|
data/schema/schema-1.0.7.yml
CHANGED
File without changes
|
data/schema/schema-1.0.8.yml
CHANGED
File without changes
|
data/schema/schema-1.0.9.yml
CHANGED
File without changes
|
data/schema/schema.yml
CHANGED
File without changes
|
data/schema/tpkg-1.0.0.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.1.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.2.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.3.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.4.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.5.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.6.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.7.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.8.dtd
CHANGED
File without changes
|
data/schema/tpkg-1.0.9.dtd
CHANGED
File without changes
|
data/schema/tpkg.dtd
CHANGED
File without changes
|
data/test/TODO
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Test that a package with no OS specified will install
|
2
|
+
# Test that a package with one matching OS will install
|
3
|
+
# Test that a package with a matching OS in a list of OSs will install
|
4
|
+
# Test that a package with one non-matching OS will not install
|
5
|
+
# Test that a package with a list of non-matching OSs will not install
|
6
|
+
|
7
|
+
# Test that a package with no architecture specified will install
|
8
|
+
# Test that a package with one matching architecture will install
|
9
|
+
# Test that a package with a matching architecture in a list of architectures will install
|
10
|
+
# Test that a package with one non-matching architecture will not install
|
11
|
+
# Test that a package with a list of non-matching architectures will not install
|
12
|
+
|
13
|
+
# Test that preinstall/postinstall/preremove/postremove are run at the right points
|
14
|
+
|
15
|
+
# Test that a package with an available dependency in version range will install
|
16
|
+
# Test that a package with an unavailable dependency won't install - dep doesn't exist
|
17
|
+
# Test that a package with an unavailable dependency won't install - dep below min version
|
18
|
+
# Test that a package with an unavailable dependency won't install - dep above max version
|
19
|
+
# Test that a package with an unavailable dependency won't install - dep doesn't match on OS
|
20
|
+
# This tests that we properly handle a dependency that matches name and version but not other characteristics
|
21
|
+
|
22
|
+
|
23
|
+
# Test that a package which conflicts in name with an already installed package will not install
|
24
|
+
# Test that a package which conflicts in files with an already installed package will not install
|
25
|
+
|
26
|
+
# Upgrade with no existing install works
|
27
|
+
# Upgrade with older install works
|
28
|
+
# Upgrade with current install fails
|
29
|
+
# Upgrade with newer version fails
|
30
|
+
# Upgrade with older version and rollback flag works
|
Binary file
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
#
|
4
|
+
# Test tpkg's ability to handle package checksums
|
5
|
+
#
|
6
|
+
|
7
|
+
class TpkgChecksumTests < Test::Unit::TestCase
|
8
|
+
include TpkgTests
|
9
|
+
|
10
|
+
def setup
|
11
|
+
Tpkg::set_prompt(false)
|
12
|
+
|
13
|
+
# Make up our regular test package
|
14
|
+
@pkgfile = make_package(:remove => ['operatingsystem', 'architecture'])
|
15
|
+
end
|
16
|
+
|
17
|
+
# The processing of creating and storing checksums during the package
|
18
|
+
# creation process is tested in make.rb
|
19
|
+
|
20
|
+
def test_verify_package_checksum
|
21
|
+
assert_nothing_raised('verify good checksum') { Tpkg::verify_package_checksum(@pkgfile) }
|
22
|
+
|
23
|
+
# Add a few characters to the inner checksummed tarball and test that
|
24
|
+
# it now fails the checksum verification
|
25
|
+
tar = Tpkg::find_tar
|
26
|
+
Dir.mktmpdir('workdir') do |workdir|
|
27
|
+
system("#{tar} -C #{workdir} -xf #{@pkgfile}") || abort
|
28
|
+
File.open(File.join(workdir, 'testpkg-1.0-1', 'tpkg.tar'), 'a') do |file|
|
29
|
+
file.write('xxxxxx')
|
30
|
+
end
|
31
|
+
badpkg = Tempfile.new('tpkgtest')
|
32
|
+
system("#{tar} -C #{workdir} -cf #{badpkg.path} testpkg-1.0-1") || abort
|
33
|
+
assert_raise(RuntimeError, 'verify bad checksum') { Tpkg::verify_package_checksum(badpkg.path) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Confirm that checksum verification also fails on something that isn't a valid package
|
37
|
+
puts '#'
|
38
|
+
puts '# Errors expected here'
|
39
|
+
puts '#'
|
40
|
+
boguspkg = Tempfile.new('tpkgtest')
|
41
|
+
boguspkg.puts('xxxxxx')
|
42
|
+
boguspkg.close
|
43
|
+
assert_raise(RuntimeError, NoMethodError, 'verify bogus non-tarball') { Tpkg::verify_package_checksum(boguspkg.path) }
|
44
|
+
# And for completeness how about something that is a tarball but not a valid package
|
45
|
+
boguspkg2 = Tempfile.new('tpkgtest')
|
46
|
+
system("#{tar} -cf #{boguspkg2.path} #{boguspkg.path}")
|
47
|
+
assert_raise(RuntimeError, NoMethodError, 'verify bogus tarball') { Tpkg::verify_package_checksum(boguspkg2.path) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def teardown
|
51
|
+
FileUtils.rm_f(@pkgfile)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#
|
4
|
+
# Test tpkg's compression feature
|
5
|
+
#
|
6
|
+
|
7
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
8
|
+
|
9
|
+
class TpkgCompressTests < Test::Unit::TestCase
|
10
|
+
include TpkgTests
|
11
|
+
def setup
|
12
|
+
Tpkg::set_prompt(false)
|
13
|
+
# Make up our regular test package
|
14
|
+
@pkgfile = make_package(:remove => ['operatingsystem', 'architecture'])
|
15
|
+
@gzip_pkgfile = make_package(:change => {'name' => 'gzip_pkg'}, :remove => ['operatingsystem', 'architecture'], :compress => 'gzip')
|
16
|
+
@bz2_pkgfile = make_package(:change => {'name' => 'bz2_pkg'}, :remove => ['operatingsystem', 'architecture'], :compress => 'bz2')
|
17
|
+
@default_compression_pkgfile = make_package(:change => {'name' => 'default_compression_pkg'}, :remove => ['operatingsystem', 'architecture'], :compress => true)
|
18
|
+
@uncompressed_pkgfile = make_package(:change => {'name' => 'uncompressed_pkg'}, :remove => ['operatingsystem', 'architecture'], :compress => false)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Given a .tpkg file, verify that we can figure out how the inner level archive tpkg.tar
|
22
|
+
# was compressed
|
23
|
+
def test_get_compression
|
24
|
+
assert(Tpkg::get_compression(@pkgfile).nil?)
|
25
|
+
assert_equal('gzip', Tpkg::get_compression(@gzip_pkgfile))
|
26
|
+
assert_equal('bz2', Tpkg::get_compression(@bz2_pkgfile))
|
27
|
+
assert(['bz2', 'gzip'].include?(Tpkg::get_compression(@default_compression_pkgfile)))
|
28
|
+
assert(Tpkg::get_compression(@uncompressed_pkgfile).nil?)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_install_compressed_pkg
|
32
|
+
Dir.mktmpdir('testroot') do |testroot|
|
33
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => [@gzip_pkgfile, @bz2_pkgfile])
|
34
|
+
assert_nothing_raised { tpkg.install([@gzip_pkgfile], PASSPHRASE) }
|
35
|
+
assert_nothing_raised { tpkg.install([@bz2_pkgfile], PASSPHRASE) }
|
36
|
+
assert_nothing_raised { tpkg.install([@default_compression_pkgfile], PASSPHRASE) }
|
37
|
+
assert_nothing_raised { tpkg.install([@uncompressed_pkgfile], PASSPHRASE) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_bad_compression_type
|
42
|
+
assert_raise(RuntimeError, 'verify bad compression type') {
|
43
|
+
make_package(:change => {'name' => 'bogus_compression_pkg'},
|
44
|
+
:remove => ['operatingsystem', 'architecture'], :compress => 'bogus')
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def teardown
|
49
|
+
FileUtils.rm_f(@pkgfile)
|
50
|
+
FileUtils.rm_f(@gzip_pkgfile)
|
51
|
+
FileUtils.rm_f(@bz2_pkgfile)
|
52
|
+
FileUtils.rm_f(@default_compression_pkgfile)
|
53
|
+
FileUtils.rm_f(@uncompressed_pkgfile)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Test tpkg's ability to resolve dependencies
|
3
|
+
#
|
4
|
+
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
class TpkgConflictTests < Test::Unit::TestCase
|
8
|
+
include TpkgTests
|
9
|
+
|
10
|
+
def setup
|
11
|
+
Tpkg::set_prompt(false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_conflict
|
15
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
16
|
+
pkgfiles = []
|
17
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
18
|
+
|
19
|
+
pkgfiles << make_package(:change => { 'name' => 'pkgA', 'version' => '1.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'], :conflicts => {'pkgB' => {}})
|
20
|
+
pkgfiles << make_package(:change => { 'name' => 'pkgB', 'version' => '1.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
21
|
+
pkgfiles << make_package(:change => { 'name' => 'pkgC', 'version' => '1.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
22
|
+
pkgfiles << make_package(:change => { 'name' => 'pkgC', 'version' => '2.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'], :conflicts => {'pkgD' => {}})
|
23
|
+
pkgfiles << make_package(:change => { 'name' => 'pkgD', 'version' => '1.0' }, :source_directory => srcdir, :remove => ['operatingsystem', 'architecture'])
|
24
|
+
|
25
|
+
# Should not be able to install both pkgA and B since A conflicts with B
|
26
|
+
Dir.mktmpdir('testroot') do |testroot|
|
27
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :base => File.join('home', 'tpkg'), :sources => pkgfiles)
|
28
|
+
assert_raise(RuntimeError) { tpkg.install(['pkgA', 'pkgB'], PASSPHRASE) }
|
29
|
+
assert_nothing_raised { tpkg.install(['pkgA'], PASSPHRASE)}
|
30
|
+
assert(!tpkg.install(['pkgB'], PASSPHRASE))
|
31
|
+
assert(tpkg.install(['pkgB'], PASSPHRASE, {:force_replace => true}))
|
32
|
+
assert_nothing_raised { tpkg.install(['pkgC=1.0', 'pkgD'], PASSPHRASE)}
|
33
|
+
# Should not be able to upgrade pgkC because new version
|
34
|
+
# of pkgC conflicts with pkgD
|
35
|
+
assert(!tpkg.upgrade(['pkgC'], PASSPHRASE))
|
36
|
+
assert(tpkg.upgrade(['pkgC'], PASSPHRASE, {:force_replace => true}))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,398 @@
|
|
1
|
+
#
|
2
|
+
# Test tpkg's crontab handling methods
|
3
|
+
#
|
4
|
+
|
5
|
+
require File.expand_path('tpkgtest', File.dirname(__FILE__))
|
6
|
+
|
7
|
+
class TpkgCrontabTests < Test::Unit::TestCase
|
8
|
+
include TpkgTests
|
9
|
+
|
10
|
+
def setup
|
11
|
+
Tpkg::set_prompt(false)
|
12
|
+
|
13
|
+
# Pretend to be an OS with cron.d support
|
14
|
+
fact = Facter::Util::Fact.new('operatingsystem')
|
15
|
+
fact.stubs(:value).returns('RedHat')
|
16
|
+
Facter.stubs(:[]).returns(fact)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_crontabs
|
20
|
+
metadata = nil
|
21
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
22
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
23
|
+
create_metadata_file(
|
24
|
+
File.join(srcdir, 'tpkg.xml'),
|
25
|
+
:change => { 'name' => 'cronpkg' },
|
26
|
+
:files => {
|
27
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'nobody'} },
|
28
|
+
'etc/cron.d/crontab' => { 'crontab' => {} } })
|
29
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
30
|
+
end
|
31
|
+
Dir.mktmpdir('testroot') do |testroot|
|
32
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
33
|
+
assert_equal(
|
34
|
+
{
|
35
|
+
"#{testroot}/opt/tpkg/etc/crontab_user" =>
|
36
|
+
{'path'=>'etc/crontab_user', 'crontab'=>{'user'=>'nobody'}},
|
37
|
+
"#{testroot}/opt/tpkg/etc/cron.d/crontab" =>
|
38
|
+
{'path'=>'etc/cron.d/crontab', 'crontab'=>{}}
|
39
|
+
},
|
40
|
+
tpkg.crontabs(metadata))
|
41
|
+
|
42
|
+
assert_equal({}, tpkg.crontabs({}))
|
43
|
+
assert_equal({}, tpkg.crontabs({:files => {}}))
|
44
|
+
assert_equal({}, tpkg.crontabs({:files => {:files => {}}}))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def test_crontab_destinations
|
48
|
+
pkg = nil
|
49
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
50
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
51
|
+
FileUtils.mkdir_p("#{srcdir}/reloc/etc/cron.d")
|
52
|
+
File.open("#{srcdir}/reloc/etc/crontab_user", 'w') do |file|
|
53
|
+
file.puts('user crontab')
|
54
|
+
end
|
55
|
+
File.open("#{srcdir}/reloc/etc/cron.d/crontab", 'w') do |file|
|
56
|
+
file.puts('cron.d crontab')
|
57
|
+
end
|
58
|
+
pkg = make_package(
|
59
|
+
:change => { 'name' => 'cronpkg' },
|
60
|
+
:source_directory => srcdir,
|
61
|
+
:files => {
|
62
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'nobody'} },
|
63
|
+
'etc/cron.d/crontab' => { 'crontab' => {} } },
|
64
|
+
:remove => ['operatingsystem', 'architecture'])
|
65
|
+
end
|
66
|
+
Dir.mktmpdir('testroot') do |testroot|
|
67
|
+
tpkg = Tpkg.new(:file_system_root => testroot, :sources => [pkg])
|
68
|
+
metadata = Tpkg::metadata_from_package(pkg)
|
69
|
+
assert_equal(
|
70
|
+
{
|
71
|
+
"#{testroot}/opt/tpkg/etc/crontab_user" => {:type=>:file, :user=>'nobody'},
|
72
|
+
"#{testroot}/opt/tpkg/etc/cron.d/crontab" => {:type=>:link, :path=>'/etc/cron.d/crontab'},
|
73
|
+
},
|
74
|
+
tpkg.crontab_destinations(metadata))
|
75
|
+
end
|
76
|
+
FileUtils.rm_f(pkg)
|
77
|
+
end
|
78
|
+
def test_crontab_destination
|
79
|
+
tpkg = Tpkg.new
|
80
|
+
assert_equal(
|
81
|
+
{:type=>:file, :user=>'nobody'},
|
82
|
+
tpkg.crontab_destination(
|
83
|
+
'/opt/tpkg/etc/crontab_user', {:crontab => {:user => 'nobody'}}))
|
84
|
+
assert_equal(
|
85
|
+
{:type=>:link, :path=>'/etc/cron.d/crontab'},
|
86
|
+
tpkg.crontab_destination(
|
87
|
+
'/opt/tpkg/etc/cron.d/crontab', {:crontab => {}}))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_install_crontabs
|
91
|
+
metadata = nil
|
92
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
93
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
94
|
+
create_metadata_file(
|
95
|
+
File.join(srcdir, 'tpkg.xml'),
|
96
|
+
:change => { 'name' => 'cronpkg' },
|
97
|
+
:files => {
|
98
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'nobody'} },
|
99
|
+
'etc/cron.d/crontab' => { 'crontab' => {} } })
|
100
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
101
|
+
end
|
102
|
+
Dir.mktmpdir('testroot') do |testroot|
|
103
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
104
|
+
tpkg.expects(:install_crontab_link).with(metadata, "#{testroot}/opt/tpkg/etc/cron.d/crontab", '/etc/cron.d/crontab')
|
105
|
+
tpkg.expects(:install_crontab_file).with(metadata, "#{testroot}/opt/tpkg/etc/crontab_user", 'nobody')
|
106
|
+
tpkg.install_crontabs(metadata)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
def test_install_crontab_link
|
110
|
+
metadata = nil
|
111
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
112
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
113
|
+
create_metadata_file(
|
114
|
+
File.join(srcdir, 'tpkg.xml'),
|
115
|
+
:change => { 'name' => 'cronpkg' },
|
116
|
+
:files => { 'etc/cron.d/crontab' => { 'crontab' => {} } })
|
117
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
118
|
+
end
|
119
|
+
Dir.mktmpdir('testroot') do |testroot|
|
120
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
121
|
+
crontab = "#{testroot}/opt/tpkg/etc/cron.d/crontab"
|
122
|
+
destination = "#{testroot}/etc/cron.d/crontab"
|
123
|
+
|
124
|
+
# Directory for link doesn't exist, directory and link are created
|
125
|
+
tpkg.install_crontab_link(metadata, crontab, destination)
|
126
|
+
assert(File.symlink?(destination))
|
127
|
+
assert_equal(crontab, File.readlink(destination))
|
128
|
+
|
129
|
+
# Link already exists, nothing is done
|
130
|
+
sleep 2
|
131
|
+
beforetime = File.lstat(destination).mtime
|
132
|
+
tpkg.install_crontab_link(metadata, crontab, destination)
|
133
|
+
assert(File.symlink?(destination))
|
134
|
+
assert_equal(crontab, File.readlink(destination))
|
135
|
+
assert_equal(beforetime, File.lstat(destination).mtime)
|
136
|
+
|
137
|
+
# Existing files or links up to 8 already exist, link created with appropriate suffix
|
138
|
+
File.delete(destination)
|
139
|
+
File.symlink('somethingelse', destination)
|
140
|
+
0.upto(8) do |i|
|
141
|
+
File.delete(destination + i.to_s) if (i != 0)
|
142
|
+
File.symlink('somethingelse', destination + i.to_s)
|
143
|
+
tpkg.install_crontab_link(metadata, crontab, destination)
|
144
|
+
assert(File.symlink?(destination + (i + 1).to_s))
|
145
|
+
assert_equal(crontab, File.readlink(destination + (i + 1).to_s))
|
146
|
+
end
|
147
|
+
|
148
|
+
# Existing files or links up to 9 already exist, exception raised
|
149
|
+
File.delete(destination + '9')
|
150
|
+
File.symlink('somethingelse', destination + '9')
|
151
|
+
assert_raise(RuntimeError) { tpkg.install_crontab_link(metadata, crontab, destination) }
|
152
|
+
end
|
153
|
+
end
|
154
|
+
def test_crontab_uoption
|
155
|
+
current_user = Etc.getpwuid.name
|
156
|
+
tpkg = Tpkg.new
|
157
|
+
assert_equal '', tpkg.crontab_uoption('ANY')
|
158
|
+
assert_equal '', tpkg.crontab_uoption(current_user)
|
159
|
+
assert_equal '-u nobody', tpkg.crontab_uoption('nobody')
|
160
|
+
end
|
161
|
+
# Test that install_crontab_file calls the crontab command with the -u
|
162
|
+
# option if the package request that the crontab be installed for a user
|
163
|
+
# other than the current user
|
164
|
+
def test_install_crontab_file_with_uoption
|
165
|
+
metadata = nil
|
166
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
167
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
168
|
+
create_metadata_file(
|
169
|
+
File.join(srcdir, 'tpkg.xml'),
|
170
|
+
:change => { 'name' => 'cronpkg' },
|
171
|
+
:files => {
|
172
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'BoguS'} }})
|
173
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
174
|
+
end
|
175
|
+
tpkg = Tpkg.new
|
176
|
+
tpkg.expects(:`).with('crontab -u nobody -l').returns('')
|
177
|
+
crontab = Tempfile.new('tpkgtest_cron')
|
178
|
+
tpkg.expects(:system).with(regexp_matches(/\Acrontab -u nobody [^-]/))
|
179
|
+
tpkg.install_crontab_file(metadata, crontab, 'nobody')
|
180
|
+
end
|
181
|
+
# And test that it omits the -u option if the crontab is for the current
|
182
|
+
# user
|
183
|
+
def test_install_crontab_file_without_uoption
|
184
|
+
current_user = Etc.getpwuid.name
|
185
|
+
metadata = nil
|
186
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
187
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
188
|
+
create_metadata_file(
|
189
|
+
File.join(srcdir, 'tpkg.xml'),
|
190
|
+
:change => { 'name' => 'cronpkg' },
|
191
|
+
:files => {
|
192
|
+
'etc/crontab_user' => { 'crontab' => {'user' => current_user} }})
|
193
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
194
|
+
end
|
195
|
+
tpkg = Tpkg.new
|
196
|
+
tpkg.expects(:`).with('crontab -l').returns('')
|
197
|
+
crontab = Tempfile.new('tpkgtest_cron')
|
198
|
+
tpkg.expects(:system).with(regexp_matches(/\Acrontab [^-]/))
|
199
|
+
tpkg.install_crontab_file(metadata, crontab, current_user)
|
200
|
+
end
|
201
|
+
# And finally, test that it properly adds the given crontab to the user's
|
202
|
+
# crontab
|
203
|
+
def test_install_crontab_file_operation
|
204
|
+
current_user = Etc.getpwuid.name
|
205
|
+
metadata = nil
|
206
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
207
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
208
|
+
create_metadata_file(
|
209
|
+
File.join(srcdir, 'tpkg.xml'),
|
210
|
+
:change => { 'name' => 'cronpkg' },
|
211
|
+
:files => {
|
212
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'BoguS'} }})
|
213
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
214
|
+
end
|
215
|
+
fake_filename = '/path/to/cronpkg-1.0.tpkg'
|
216
|
+
metadata[:filename] = fake_filename
|
217
|
+
Dir.mktmpdir('testroot') do |testroot|
|
218
|
+
existing_contents = "* * * * * /existing/job\n"
|
219
|
+
user_crontab = Tempfile.new('tpkgtest_cron')
|
220
|
+
user_crontab.write existing_contents
|
221
|
+
user_crontab.close
|
222
|
+
package_crontab = "#{testroot}/opt/tpkg/etc/crontab_user"
|
223
|
+
FileUtils.mkdir_p(File.dirname(package_crontab))
|
224
|
+
new_contents = "1 2 * * * /new/job\n"
|
225
|
+
File.open(package_crontab, 'w') do |file|
|
226
|
+
file.write new_contents
|
227
|
+
end
|
228
|
+
tpkg = Tpkg.new(
|
229
|
+
:file_system_root => testroot,
|
230
|
+
:cmd_crontab => File.join(TESTCMDDIR, "crontab -f #{user_crontab.path}"))
|
231
|
+
tpkg.install_crontab_file(metadata, package_crontab, current_user)
|
232
|
+
user_crontab.open
|
233
|
+
assert_equal(
|
234
|
+
existing_contents +
|
235
|
+
"### TPKG START - #{testroot}/opt/tpkg - #{File.basename(fake_filename)}\n" +
|
236
|
+
new_contents +
|
237
|
+
"### TPKG END - #{testroot}/opt/tpkg - #{File.basename(fake_filename)}\n",
|
238
|
+
user_crontab.read)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
def test_remove_crontabs
|
242
|
+
metadata = nil
|
243
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
244
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
245
|
+
create_metadata_file(
|
246
|
+
File.join(srcdir, 'tpkg.xml'),
|
247
|
+
:change => { 'name' => 'cronpkg' },
|
248
|
+
:files => {
|
249
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'nobody'} },
|
250
|
+
'etc/cron.d/crontab' => { 'crontab' => {} } })
|
251
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
252
|
+
end
|
253
|
+
Dir.mktmpdir('testroot') do |testroot|
|
254
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
255
|
+
tpkg.expects(:remove_crontab_file).with(metadata, 'nobody')
|
256
|
+
tpkg.expects(:remove_crontab_link).with(metadata, "#{testroot}/opt/tpkg/etc/cron.d/crontab", '/etc/cron.d/crontab')
|
257
|
+
tpkg.remove_crontabs(metadata)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
def test_remove_crontab_link
|
261
|
+
metadata = nil
|
262
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
263
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
264
|
+
create_metadata_file(
|
265
|
+
File.join(srcdir, 'tpkg.xml'),
|
266
|
+
:change => { 'name' => 'cronpkg' },
|
267
|
+
:files => { 'etc/cron.d/crontab' => { 'crontab' => {} } })
|
268
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
269
|
+
end
|
270
|
+
Dir.mktmpdir('testroot') do |testroot|
|
271
|
+
tpkg = Tpkg.new(:file_system_root => testroot)
|
272
|
+
crontab = File.join(testroot, '/opt/tpkg/etc/cron.d/crontab')
|
273
|
+
destination = File.join(testroot, '/etc/cron.d/crontab')
|
274
|
+
|
275
|
+
# Standard symlink using the base name is removed
|
276
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
277
|
+
File.symlink(crontab, destination)
|
278
|
+
tpkg.remove_crontab_link(metadata, crontab, destination)
|
279
|
+
refute File.symlink?(destination)
|
280
|
+
refute File.exist?(destination)
|
281
|
+
|
282
|
+
# Links with suffixes from 1..9 are removed
|
283
|
+
1.upto(9) do |i|
|
284
|
+
FileUtils.rm(Dir.glob(destination + '*'))
|
285
|
+
File.symlink(crontab, destination + i.to_s)
|
286
|
+
File.symlink(crontab, destination + '1') if (i != 1)
|
287
|
+
2.upto(i-1) do |j|
|
288
|
+
File.symlink('somethingelse', destination + j.to_s)
|
289
|
+
end
|
290
|
+
tpkg.remove_crontab_link(metadata, crontab, destination)
|
291
|
+
refute File.exist?(destination)
|
292
|
+
refute File.symlink?(destination)
|
293
|
+
refute File.exist?(destination + '1')
|
294
|
+
refute File.symlink?(destination + '1')
|
295
|
+
2.upto(i-1) do |j|
|
296
|
+
assert(File.symlink?(destination + j.to_s))
|
297
|
+
assert_equal('somethingelse', File.readlink(destination + j.to_s))
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# Links with suffixes of 0 or 10 are left alone
|
302
|
+
File.symlink(crontab, destination + '0')
|
303
|
+
File.symlink(crontab, destination + '10')
|
304
|
+
tpkg.remove_crontab_link(metadata, crontab, destination)
|
305
|
+
assert File.symlink?(destination + '0')
|
306
|
+
assert_equal crontab, File.readlink(destination + '0')
|
307
|
+
assert File.symlink?(destination + '10')
|
308
|
+
assert_equal crontab, File.readlink(destination + '10')
|
309
|
+
end
|
310
|
+
end
|
311
|
+
def test_remove_crontab_file_with_uoption
|
312
|
+
metadata = nil
|
313
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
314
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
315
|
+
create_metadata_file(
|
316
|
+
File.join(srcdir, 'tpkg.xml'),
|
317
|
+
:change => { 'name' => 'cronpkg' },
|
318
|
+
:files => {
|
319
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'BoguS'} }})
|
320
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
321
|
+
end
|
322
|
+
tpkg = Tpkg.new
|
323
|
+
tpkg.expects(:`).with('crontab -u nobody -l').returns('')
|
324
|
+
crontab = Tempfile.new('tpkgtest_cron')
|
325
|
+
tpkg.expects(:system).with(regexp_matches(/\Acrontab -u nobody [^-]/))
|
326
|
+
tpkg.remove_crontab_file(metadata, 'nobody')
|
327
|
+
end
|
328
|
+
def test_remove_crontab_file_without_uoption
|
329
|
+
current_user = Etc.getpwuid.name
|
330
|
+
metadata = nil
|
331
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
332
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
333
|
+
create_metadata_file(
|
334
|
+
File.join(srcdir, 'tpkg.xml'),
|
335
|
+
:change => { 'name' => 'cronpkg' },
|
336
|
+
:files => {
|
337
|
+
'etc/crontab_user' => { 'crontab' => {'user' => current_user} }})
|
338
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
339
|
+
end
|
340
|
+
tpkg = Tpkg.new
|
341
|
+
tpkg.expects(:`).with('crontab -l').returns('')
|
342
|
+
crontab = Tempfile.new('tpkgtest_cron')
|
343
|
+
tpkg.expects(:system).with(regexp_matches(/\Acrontab [^-]/))
|
344
|
+
tpkg.remove_crontab_file(metadata, current_user)
|
345
|
+
end
|
346
|
+
def test_remove_crontab_file_operation
|
347
|
+
current_user = Etc.getpwuid.name
|
348
|
+
metadata = nil
|
349
|
+
Dir.mktmpdir('srcdir') do |srcdir|
|
350
|
+
FileUtils.cp(File.join(TESTPKGDIR, 'tpkg-nofiles.xml'), File.join(srcdir, 'tpkg.xml'))
|
351
|
+
create_metadata_file(
|
352
|
+
File.join(srcdir, 'tpkg.xml'),
|
353
|
+
:change => { 'name' => 'cronpkg' },
|
354
|
+
:files => {
|
355
|
+
'etc/crontab_user' => { 'crontab' => {'user' => 'BoguS'} }})
|
356
|
+
metadata = Metadata.new(File.read(File.join(srcdir, 'tpkg.xml')), 'xml')
|
357
|
+
end
|
358
|
+
fake_filename = '/path/to/cronpkg-1.0.tpkg'
|
359
|
+
metadata[:filename] = fake_filename
|
360
|
+
Dir.mktmpdir('testroot') do |testroot|
|
361
|
+
testbase = "#{testroot}/opt/tpkg"
|
362
|
+
not_my_part_one = <<-EOF.gsub(/^\s+/, '')
|
363
|
+
* * * * * /this/is/not/a/tpkg/cronjob
|
364
|
+
EOF
|
365
|
+
my_part_one = <<-EOF.gsub(/^\s+/, '')
|
366
|
+
### TPKG START - #{testbase} - #{File.basename(metadata[:filename])}
|
367
|
+
* * * * * /this/is/my/crontab
|
368
|
+
### TPKG END - #{testbase} - #{File.basename(metadata[:filename])}
|
369
|
+
EOF
|
370
|
+
not_my_part_two = <<-EOF.gsub(/^\s+/, '')
|
371
|
+
### TPKG START - #{testbase} - someotherpkg-2.34.tpkg
|
372
|
+
* * * * * /this/is/not/my/crontab
|
373
|
+
### TPKG END - #{testbase} - someotherpkg-2.34.tpkg
|
374
|
+
### TPKG START - /path/to/other/base - #{File.basename(metadata[:filename])}
|
375
|
+
* * * * * /this/is/not/my/crontab
|
376
|
+
### TPKG END - /path/to/other/base - #{File.basename(metadata[:filename])}
|
377
|
+
EOF
|
378
|
+
my_part_two = <<-EOF.gsub(/^\s+/, '')
|
379
|
+
### TPKG START - #{testbase} - #{File.basename(metadata[:filename])}
|
380
|
+
* * * * * /this/is/my/crontab
|
381
|
+
### TPKG END - #{testbase} - #{File.basename(metadata[:filename])}
|
382
|
+
EOF
|
383
|
+
user_crontab = Tempfile.new('tpkgtest_cron')
|
384
|
+
user_crontab.write not_my_part_one + my_part_one + not_my_part_two + my_part_two
|
385
|
+
user_crontab.close
|
386
|
+
tpkg = Tpkg.new(
|
387
|
+
:file_system_root => testroot,
|
388
|
+
:cmd_crontab => File.join(TESTCMDDIR, "crontab -f #{user_crontab.path}"))
|
389
|
+
tpkg.remove_crontab_file(metadata, current_user)
|
390
|
+
user_crontab.open
|
391
|
+
assert_equal(not_my_part_one + not_my_part_two, user_crontab.read)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
def teardown
|
396
|
+
Facter.unstub(:[])
|
397
|
+
end
|
398
|
+
end
|