예제 #1
0
    def testCheckArgs(self):
        self.assertRaises(ValueError, TMContext._checkArgs, None)
        self.assertRaises(ValueError, TMContext._checkArgs, [])
        self.assertRaises(ValueError, TMContext._checkArgs, ['scriptname'])
        self.assertRaises(ValueError, TMContext._checkArgs, ['scriptname', 'dummy context'])

        # should be ok with these fake args
        TMContext._checkArgs(['scriptname', 'context', 'disk'])
예제 #2
0
    def testParseContextFile(self):
        try:
            _, filename = tempfile.mkstemp()
            with open(filename, 'wb') as f:
                f.write(self.TEST_CONTEXT)
    
            params = TMContext._parseContextFile(filename)

            self.assertEqual(params['context_method'], 'cloud-init')
            self.assertEqual(params['authorized_keys'], 'DUMMY_DATA')
            self.assertEqual(params['user_data'], 'DUMMY_DATA')

        finally:
            os.remove(filename)
예제 #3
0
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import sys

sys.path.append('/var/lib/stratuslab/python')

from stratuslab.tm.TMContext import TMContext

if __name__ == '__main__':
    try:
        context_files = sys.argv
        context_files.append('/var/share/stratuslab/context/init.sh')
        context_files.append('/var/share/stratuslab/context/epilog.sh')
        context_files.append('/var/share/stratuslab/context/prolog.sh')
        tm = TMContext(sys.argv)
        tm.run()
    except Exception, e:
        print >> sys.stderr, 'ERROR MESSAGE --8<------'
        print >> sys.stderr, '%s: %s' % (os.path.basename(__file__), e)
        print >> sys.stderr, 'ERROR MESSAGE ------>8--'
        if TMContext.PRINT_TRACE_ON_ERROR: 
            raise
        sys.exit(1)